我怎样才能正确重定向到路线?
\n我的应用程序必须具有一定的路由安全性,我尝试使用 GoRouter\n 来做到这一点,但它总是执行一次重定向并总是返回到主页。
\n只有 3 条安全路径(个人资料、订单、收藏夹),如果您尚未登录,则必须返回登录。
\n但是当我将 3 个路由中的任何一个放入 url 时,它会将我重定向到登录名并立即到主页(这是不应该发生的情况)
\n有人可以帮助我吗?\n我多次改变了逻辑,但我总是回到同一点。
\nclass 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)