[英]Flutter go_router parameters within ShellRoute not working
I am using go_router and need have setup a ShellRoute
.我正在使用go_router并且需要设置一个ShellRoute
。 It is working fine so far.到目前为止它工作正常。 Now one of the routes
inside that ShellRoute
should have a route with params
.现在ShellRoute
中的一条routes
应该有一条带有params
的路线。 And I can not make it work..而且我无法让它工作..
This is my setup:这是我的设置:
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']!,
),
),
);
},
),
],
),
...
And I am trying to push
to ProjectDetailScaffold
like this:我正在尝试像这样push
送到ProjectDetailScaffold
:
rootNavigatorKey.currentContext!.push(
'/projects/wishlists',
);
But I get an error
that no route exists for /projects/wishlists
...但是我得到一个error
,指出/projects/wishlists
不存在路由 ...
What am I missing here?我在这里错过了什么?
Let me know if you need any more info.如果您需要更多信息,请告诉我。
I figured it out by myself:我自己弄明白了:
The problem was that I specified path
of the subRoute wrong.问题是我指定的子path
错误。 I added it's parent path as well when I only need to add :projectTitle
.当我只需要添加:projectTitle
时,我也添加了它的父路径。 Here is the working solution:这是工作解决方案:
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.