我正在使用 go router我的 flutter web 应用程序的插件,但我没有找到任何方法在导航中进行推送替换。
不仅仅是推送替换,我们可以做任何其他类型的导航链接吗
- pushNamedAndRemoveUntil
- 弹出直到 因为任何系统都必须需要这些导航选项!
我尝试过的
- context.go(userStorage.redirectURL!);
- GoRouter.of(context).go(PagesCollection.adminDashboard);
他们只推送下一页,不替换
注意:我想在 go router 中使用这个功能
最佳答案
我以前遇到过同样的问题。然后这种方式对我有用 首先你需要避免嵌套路由:
final GoRouter router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const OnboardingScreen(),
),
GoRoute(
path: '/login',
builder: (BuildContext context, GoRouterState state) => LoginScreen(),
),
GoRoute(
path: '/signup',
builder: (BuildContext context, GoRouterState state) =>
const SignupScreen(),
),
],
);
使用上面的代码而不是像这样嵌套:
final GoRouter router = GoRouter(
routes: <GoRoute>[
GoRoute(
routes: <GoRoute>[
GoRoute(
path: 'login',
builder: (BuildContext context, GoRouterState state) => LoginScreen(),
),
GoRoute(
path: '/signup',
builder: (BuildContext context, GoRouterState state) =>
const SignupScreen(),
),
],
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const OnboardingScreen(),
),
],
);
这将使您能够替换上面的 OnboardingScreen(),例如。所以接下来你可以使用 pushreplacement future :
context.go("/routname");
或者 GoRouter.of(context).go("/routname"); 如果你不想更换,那么可以使用:
context.push("/routname");
或
GoRouter.of(context).push("/routname");
关于flutter - 我如何在 flutter [go router] 中使用 go router 插件进行推送替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70547019/