Before entering the page, I would appreciate if you can suggest a method that I can redirect to the error page when the pathname is not correct. When I type pushNamed(“/2”), if there is no page with the pathname “/2”, it should redirect to the error page.
When the pathname of my page is wrong in the auto guard part, it does not enter the auto guard queries. throws error and the guard part does not work.
I can't give my class to check in my config file.
final _appRouter = AppRouter(checkIfBookExists: CheckIfBookExists());
class CheckIfExists extends AutoRouteGuard { @override Future onNavigation(
NavigationResolver resolver, StackRouter router) async {
final pathName = resolver.route.toPageRouteInfo().routeName;
final pathIsAvaliable = _isKnownRoute("/$pathName");
if (pathIsAvaliable)
resolver.next();
else
router.push(const ProblemRoute());
}
bool _isKnownRoute(String path) { final knownPaths = [ "/SplashRoute", "/LoginRoute", "/UpdateWarningRoute", "/ChooseProcessRoute", ]; return knownPaths.contains(path); } }
Before entering the page, I would appreciate if you can suggest a method that I can redirect to the error page when the pathname is not correct. When I type pushNamed(“/2”), if there is no page with the pathname “/2”, it should redirect to the error page.