Flutter中从启动页跳转至StatefulShellRoute.indexedStack路由的方法
路由跳转问题解决方案
问题原因
你当前的context.goNamed('home')无法生效,是因为路由配置里没有名为home的路由,而且StatefulShellRoute.indexedStack作为壳路由本身不需要独立命名,它是通过下属的StatefulShellBranch路由来触发加载HomeScreen的。
解决步骤
直接跳转到StatefulShellBranch下已定义的具体路由即可,比如你配置的第一个分支account路由:
修改后的splash_screen.dart代码
Timer( const Duration(seconds: 3), () { isOnboardingCompleted ? isLoggedIn ? context.goNamed('account') // 替换home为已定义的分支路由名称account : context.goNamed('signin') : context.goNamed('onboarding'); }, );
补充说明
StatefulShellRoute.indexedStack是底部导航的壳容器,当你跳转到它下属任意一个分支路由(比如/account)时,GoRouter会自动加载HomeScreen并显示对应分支的页面。- 后续新增底部导航页面时,只需在
branches中添加新的StatefulShellBranch,跳转对应分支的路由名称即可。
内容的提问来源于stack exchange,提问作者Mehedi Hasan
相关产品推荐
相关产品推荐

