![](/img/trans.png)
[英]Flutter go_router: how to use ShellRoute with an expanded child?
[英]Flutter go_router parameters within ShellRoute not working
我正在使用go_router并且需要设置一个ShellRoute
。 到目前为止它工作正常。 现在ShellRoute
中的一条routes
应该有一条带有params
的路线。 而且我无法让它工作..
这是我的设置:
final rootNavigatorKey = GlobalKey<NavigatorState>();
class AppRouter {
static final _shellNavigatorKey = GlobalKey<NavigatorState>();
static final router = GoRouter(
initialLocation: IntroView.path,
debugLogDiagnostics: true,
navigatorKey: rootNavigatorKey,
routes: [
ShellRoute(
navigatorKey: _shellNavigatorKey,
pageBuilder: (context, state, child) {
return NoTransitionPage(
child: ScaffoldView(
initLocation: state.location,
child: child,
),
);
},
routes: [
GoRoute(
name: ProjectsView.name,
path: ProjectsView.path,
parentNavigatorKey: _shellNavigatorKey,
pageBuilder: (context, state) {
return const FadePageTransition(
page: ProjectsView(),
);
},
routes: [
GoRoute(
parentNavigatorKey: rootNavigatorKey,
path: 'projects/:projectTitle',
pageBuilder: (context, state) {
return FadePageTransition(
page: ProjectDetailScaffold(
project: Projects.values.byName(
state.params['projectTitle']!,
),
),
);
},
),
],
),
...
我正在尝试像这样push
送到ProjectDetailScaffold
:
rootNavigatorKey.currentContext!.push(
'/projects/wishlists',
);
但是我得到一个error
,指出/projects/wishlists
不存在路由 ...
我在这里错过了什么?
如果您需要更多信息,请告诉我。
我自己弄明白了:
问题是我指定的子path
错误。 当我只需要添加:projectTitle
时,我也添加了它的父路径。 这是工作解决方案:
GoRoute(
parentNavigatorKey: rootNavigatorKey,
path: ':projectTitle',
pageBuilder: (context, state) {
return FadePageTransition(
page: ProjectDetailScaffold(
project: Projects.values.byName(
state.params['projectTitle']!,
),
),
);
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.