使用
GoRouter
,可以使用GoRoute
属性将ShellRoute's
添加为父parentNavigatorKey
导航器。
但是,在某些情况下,
GoRoute
的直接父级 ShellRoute
也需要与 GoRoute itself
一起添加。
想象一个父导航器正在添加管理他们自己的过渡并包含他们自己的
ShellRoutes
的工作表,为页面提供导航器。
我想将新工作表添加到父工作表导航器。该工作表包含自己的导航器和自己的页面堆栈。
如果
ShellRoute
也有一个 parentNavigatorKey
属性,那么当我们从任何地方推送一个 GoRoute
到一个特定的导航器时,它会带它的父 ShellRoute 一起。
ShellRoute(
navigatorKey: _sheetNavigator,
pageBuilder: (context, state, child) => CustomSheetRoute<T>(child: child),
routes: [
GoRoute(
path: '/',
builder: (context, state) => const Page1(),
),
GoRoute(
path: '/page2',
builder: (context, state) => const Page2(),
routes: [
ShellRoute(
parentNavigatorKey: _sheetNavigator, // add this
pageBuilder: (context, state, child) => CustomSheetRoute<T>(child: child),
routes [
GoRoute(
path: '/page3',
builder: (context, state) => const Page3(),
),
GoRoute(
path: '/page4',
builder: (context, state) => const Page4(),
routes: [
GoRoute(
path: '/page5',
builder: (context, state) => const Page5(),
),
],
],
],
),
],
),
],
),
因此,当向 /page3 发出 go 请求时,它向工作表导航器添加了一个
CustomSheetRoute
,并在新导航器中显示了第 3 页。
这可能吗?