I have the following router config
final GlobalKey<NavigatorState> rootNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> bottomHomeNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'bottomHomeNavigatorKey');
final GlobalKey<NavigatorState> bottomSecondNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'bottomSecondNavigatorKey');
final GoRouter router = GoRouter(
initialLocation: '/home',
navigatorKey: rootNavigatorKey,
routes: [
GoRoute(
path: '/',
redirect: (context, state) {
// debugger();
if (state.fullPath == null || state.fullPath == '/') {
return '/home';
}
return state.fullPath;
},
parentNavigatorKey: rootNavigatorKey,
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, child) => MainPage(child: child),
parentNavigatorKey: rootNavigatorKey,
branches: [
StatefulShellBranch(
navigatorKey: bottomHomeNavigatorKey,
routes: [
GoRoute(
path: 'home',
parentNavigatorKey: bottomHomeNavigatorKey,
builder: (context, state) => const HomePage(),
),
],
),
StatefulShellBranch(
navigatorKey: bottomSecondNavigatorKey,
routes: [
GoRoute(
path: 'second',
parentNavigatorKey: bottomSecondNavigatorKey,
builder: (context, state) => const SecondPage(),
),
],
),
],
),
GoRoute(
path: 'orders',
builder: (context, state) => const OrdersPage(),
parentNavigatorKey: rootNavigatorKey,
routes: [
GoRoute(
path: ':orderId',
parentNavigatorKey: rootNavigatorKey,
builder: (context, state) => SingleOrderPage(
orderId: state.pathParameters['orderId'],
),
),
],
),
],
),
GoRoute(
path: '/splash',
parentNavigatorKey: rootNavigatorKey,
builder: (context, state) => const SplashPage(),
),
],
);
What I need is to have root page with BottomNavigationBar
working with StatefulShellRoute.indexedStack
.
But when I go to /orders
, I want a new page over the MainPage
, not replacing.
I tried to put GoRoute('/orders')
into one of StatefulShellBranch
s, but it just builds the orders page inside the MainPage
. And I can’t provide the rootNavigatorKey
to it.
Can’t figure out the way to make it work.