import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(
RootScreen(),
);
}
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (_, __) => ScreenOne(),
routes: [
GoRoute(
path: 'two',
builder: (_, __) => ScreenTwo(),
routes: [
GoRoute(
path: 'three',
builder: (_, __) => ScreenThree(),
),
],
),
],
),
],
);
class RootScreen extends StatelessWidget {
const RootScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
);
}
}
class ScreenOne extends StatelessWidget {
const ScreenOne({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final router = GoRouter.of(context);
return Scaffold(
appBar: AppBar(
title: Text(router.location),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.go('/two');
},
child: Text('Go'),
),
),
);
}
}
class ScreenTwo extends StatelessWidget {
const ScreenTwo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(router.location),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.go('/two/three');
},
child: Text('Go'),
),
),
);
}
}
class ScreenThree extends StatelessWidget {
const ScreenThree({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(router.location),
),
body: Center(
child: Text('three'),
),
);
}
}
Steps to Reproduce
Reproducible Code
the above code has three nested routes
I would expect that if I pop in following order /two/three -> /two -> / GoRouter.of(context).location would also reflect the correct route location (/two/three -> /two -> /); however, the second pop() does not reflect correct location (/two/three -> /two/ -> /two/). The Appbar in the following video shows GoRouter.of(context).location value. The first pop() and second pop() results in same route location. If I just push one route and pop() the location gets correctly reset.
Simulator.Screen.Recording.-.iPhone.13.Pro.Max.-.2022-12-27.at.16.44.50.mp4