小编shr*_*t91的帖子

如何使用 GoRouter 正确重定向到路由?

我怎样才能正确重定向到路线?

\n

我的应用程序必须具有一定的路由安全性,我尝试使用 GoRouter\n 来做到这一点,但它总是执行一次重定向并总是返回到主页。

\n

只有 3 条安全路径(个人资料、订单、收藏夹),如果您尚未登录,则必须返回登录。

\n

但是当我将 3 个路由中的任何一个放入 url 时,它会将我重定向到登录名并立即到主页(这是不应该发生的情况)

\n

有人可以帮助我吗?\n我多次改变了逻辑,但我总是回到同一点。

\n
class AppRouter {\n  final SessionCubit sessionCubit;\n\n  GoRouter get router => _goRouter;\n\n  AppRouter(this.sessionCubit);\n\n  late final GoRouter _goRouter = GoRouter(\n    refreshListenable: GoRouterRefreshStream(sessionCubit.stream),\n    initialLocation: APP_PAGE.home.toPath,\n    routes: <GoRoute>[\n      GoRoute(\n        path: APP_PAGE.home.toPath,\n        name: APP_PAGE.home.toName,\n        builder: (context, state) => MyHomePage(),\n      ),\n      GoRoute(\n        path: APP_PAGE.login.toPath,\n        name: APP_PAGE.login.toName,\n        builder: (context, state) => const LoginPage(),\n      ),\n      GoRoute(\n        path: APP_PAGE.profile.toPath,\n        name: APP_PAGE.profile.toName,\n        builder: (context, state) => MyProfile(),\n      ),\n      GoRoute(\n        path: APP_PAGE.page1.toPath,\n        name: …
Run Code Online (Sandbox Code Playgroud)

session redirect dart flutter flutter-go-router

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

dart ×1

flutter ×1

flutter-go-router ×1

redirect ×1

session ×1