使用context.push('/profile/check');
时,builder
函数未被调用,因此Text("Check")
显示在AppScaffold
内部。
late final GoRouter router = GoRouter(
initialLocation: '/',
refreshListenable: appService,
navigatorKey: _rootNavigatorKey,
routes: <RouteBase>[
ShellRoute(
navigatorKey: _rootShellNavigatorKey,
builder: (BuildContext context, GoRouterState state, child) => AppScaffold(
child: child,
),
routes: [
GoRoute(
parentNavigatorKey: _rootShellNavigatorKey,
path: '/',
builder: (BuildContext context, GoRouterState state) {
return HomeScreen();
},
),
GoRoute(
parentNavigatorKey: _rootShellNavigatorKey,
path: '/profile',
builder: (BuildContext context, GoRouterState state) {
return ProfilePageView();
},
routes: [
ShellRoute(
builder: (context, state, child) {
print('builder function not being called');
return Text("hello world");
},
routes: [
GoRoute(
path: 'check',
builder: (BuildContext context, GoRouterState state) {
return Center(
child: Text("Check"),
);
},
),
GoRoute(
path: 'test',
builder: (BuildContext context, GoRouterState state) {
return Center(
child: Text("Test"),
);
},
),
],
),
],
),
],
),
],
);
1条答案
按热度按时间0lvr5msh1#
如果遇到同样的问题,使用
GoRouter.of(context).go('...');
,一切都应该正常