Problem: I want to navigate to the shell route when a user is logged in and the login page when no one is logged in. What developers usually do is redirect the route to another one when user is logged in but I can't redirect the route to a shell route because I don't know how.
This is my router. I am using nested navigation to implement bottom navigation bar.
GoRouter router() {
return GoRouter(
debugLogDiagnostics: true,
initialLocation: Routes.logIn.path,
routes: _routes,
);
}
List<RouteBase> get _routes => <RouteBase>[
GoRoute(
name: Routes.logIn.name,
path: Routes.logIn.path,
builder: (context, state) {
return const LogInScreen();
},
),
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) {
return MainScreen(child: child);
},
routes: <RouteBase>[
GoRoute(path: Routes.home.path,name: Routes.home.name,builder: (_,__) => const HomeScreen()),
]
)
];
And this main file.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
builder: (_, __) => MaterialApp.router(
routerConfig: router(),
routeInformationParser: router().routeInformationParser,
routerDelegate: router().routerDelegate,
routeInformationProvider: router().routeInformationProvider,
theme: AppTheme.lightTheme,
));
}
}