I’m running into an issue where when I attempt to go “back” via Navigator.pop(context) or Navigator.of(context).pop, the previous page attempts to rebuild in GoRouter, causing an error because I’m not passing in the required parameters. I thought flutter navigation kept the build/state of previous pages… not having that defeats the entire point of the nav stack.
i.e., consider this route setup, where the user opens the app to LandingPage(), then clicks a button which navs to InnerPage() with the “necessaryParam.” Then, from InnerPage, they route to InnerPage2(), where they click a “back” button that triggers something to the effect of Navigator.pop(context). This routes the user back to InnerPage(), but throws an exception because “necessaryParam” isn’t passed.
Why is it rebuilding instead of popping InnerPage2() off the nav stack? Is the nav stack just a stack of routes to rebuild on pop()? I remember it saving state, though, so that doesn’t seem right. Any insight would be much appreciated.
I realize a solution would be to just brute force repass the params from InnerPage2 using context.goNamed(“inner”, extra: paramObject) instead of Navigator.pop(context), but if the nav stack is maintained, this would be a very a clumsy and inefficient approach as the nav stack would just continue to grow indefinitely, which seems very wrong.
routes: <RouteBase>[
GoRoute(
path: '/landing',
builder: (BuildContext context, GoRouterState state) =>
LandingPage(),
routes: <RouteBase>[
GoRoute(
path: 'inner',
name: 'inner',
builder: (BuildContext context, GoRouterState state){
// extract params from state.extra
ParamObject? params = state.extra != null ? state.extra as ParamObject : null;
var necessaryParam = params?.variable
if(necessaryParam != null)
{
return InnerPage(param: necessaryParam)
}
else{
throw Exception("necessaryParam missing!");
},
routes: <RouteBase>[
GoRoute(
path: 'inner2',
name: 'inner2',
builder: (BuildContext context, GoRouterState state){
return InnerPage2()
},
),
]
),
],
),
],
2