getx
getx copied to clipboard
The middleware will not be triggered if I use nested navigation
I refer to official documentation to implement the nested navigation.
https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md#nested-navigation
For nested navigation, the GetX works fine.
But the middleware will not take effect in nested navigation
class AuthorizedRouterGuard extends GetMiddleware {
@override
RouteSettings? redirect(String? route) {
var tokenCtrl = Get.find<TokenController>();
return JwtDecoder.isExpired(tokenCtrl.accessToken!)
? const RouteSettings(name: AppRoutes.password)
: null;
}
}
Navigator(
key: Get.nestedKey(1),
initialRoute: AppRoutes.home,
onGenerateRoute: (settings) {
if (settings.name == "/home") {
return GetPageRoute(
settings: settings,
page: () => const HomePage(),
middlewares: [AuthorizedRouterGuard()],
transition: Transition.topLevel,
);
} else if (settings.name == "/store") {
return GetPageRoute(
settings: settings,
page: () => const StoresPage(),
middlewares: [AuthorizedRouterGuard()],
transition: Transition.topLevel,
);
} else if (settings.name == "/catalogues") {
return GetPageRoute(
settings: settings,
page: () => const CatalogueAllCategoriesPage(),
middlewares: [AuthorizedRouterGuard()],
transition: Transition.topLevel,
);
} else if (settings.name == "/me") {
return GetPageRoute(
settings: settings,
page: () => const MePage(),
middlewares: [AuthorizedRouterGuard()],
transition: Transition.topLevel,
);
}
return null;
},
et.toNamed(tabRoutes[index], id: 1);
Nested navigation can work, but AuthorizedRouterGuard will not be triggered.
Unless remove 'Id' in Get.toNamed like below
Get.toNamed(tabRoutes[index]);
But this is not what I want, I will be a normal navigation, popup the page as normal, not nested navigation.
did you find any solution to this?