I am using using go_router 9.0.1 and go_router_builder 2.2.0 with riverpod 2.3.6. I have implemented go_router in my project and by default the package maintain the state of the previous page when using going to a sub-route. In my case I want that each time i go to a page, this same page reload/rebuild itself.
For example I have 2 routes :
page1
with subroutes likepage1/sub1Page1
or -page1/sub2Page1
page2
with subroutes likepage2/sub1Page1
or -page2/sub2Page1
If I go from page1
to page1/sub1Page1
using the Page1().go(context)
method since I am using the type safe methods. I want to go back from page1/sub1Page1
to the page1
with the Page1().go(context)
the state of the my riverpod provider is the same. It store the Page1
widget state somewhere meaning that I need to manually reset my providers manually using ref.invalidate(myProvider)
before pushing another page. Does a solution exist to have this behavior ?
My current simplify implementation of go_router:
GoRouter(
routes: $appRoutes,
initialLocation: initialLocation,
debugLogDiagnostics: true,
);
@TypedShellRoute<HomeRoute>(
routes: <TypedRoute<GoRouteData>>[
TypedGoRoute<Page1Route>(
path: Page1Route.path,
name: Page1Route.name,
routes: <TypedGoRoute<GoRouteData>>[
TypedGoRoute<Sub1Page1>(
path: Sub1Page1.path,
name: Sub1Page1.name,
),
TypedGoRoute<Sub2Page1>(
path: Sub2Page1.path,
name: Sub2Page1.name,
),
]
TypedGoRoute<Page2>(
path: Page2.path,
name: Page2.name,
),
]);
class HomeRoute extends ShellRouteData {
const HomeRoute();
@override
Widget builder(BuildContext context, GoRouterState state, Widget navigator) =>
Layout(child: navigator);
}
class Page1 extends GoRouteData {
const ProjectsRoute();
static const String name = kNamePage1;
static const String path = kPathPage1 ;
@override
Widget build(BuildContext context, GoRouterState state) => Page1Screen();
}
// Note that all the page or subpage are declared exactly as above.