You should
- give "initialLocation" parameter to your "GoRouter"
- give "routes" parameter to your "ShellRoute"
After doing these, you will understand why you don't need to add "path" parameter to your ShellRoute.
final GoRouter router = GoRouter(
navigatorKey: _rootNavigatorKey,
initialLocation: '/home',
routes: <RouteBase>[
/// Application shell
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (BuildContext context, GoRouterState state, Widget child) {
return ScaffoldWithNavBar(child: child);
},
routes: <RouteBase>[
/// The first screen after login.
GoRoute(
path: '/home',
builder: (BuildContext context, GoRouterState state) {
return const HomeScreen();
},
),
/// Second screen on the navigation bar
GoRoute(
path: '/discover',
builder: (BuildContext context, GoRouterState state) {
return const DiscoverScreen();
},
///Post Detail Screen inside of Discover Screen
routes: <RouteBase>[
GoRoute(
path: 'post_detail',
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const PostDetailScreen();
},
),
],
),
],
),
],
);
You can use context.go('/discover')
in your ScaffoldWithNavBar() widget, when user tap the one of the bottom navigation bar item.