Flutter GetX 路由将重定向到 initialRoute

Flutter GetX routing will redirected to initialRoute

我目前正在调查以下问题:当我第一次尝试使用“xyz.com/invite/dd/dd”等 link 参数打开页面时,我会立即定向到初始路径“/” .当我再次在同一个选项卡中执行此操作时,它将起作用并将我重定向到给定页面“/invite/dd/dd”。

这是第一次尝试的控制台日志:

The following message was thrown:
Could not navigate to initial route.
The requested route name was: "/invite/dd/dd"
There was no corresponding route in the app, and therefore the initial route specified will be ignored and "/" will be used instead.

控制台在同一选项卡中记录第二次尝试:

[GETX] GOING TO ROUTE /dashboard
[GETX] GOING TO ROUTE /invite/dd/dd
[GETX] GOING TO ROUTE /invite/dd/dd
[log] INVITE PAGE!

第二次尝试加载页面时一切正常!

来自 main.dart 中 GetMaterialAPP 的源代码:

return GetMaterialApp(
            // initialBinding: AuthBinding(),
              initialRoute: RootRoute,
              opaqueRoute: true,
              unknownRoute: GetPage(name: "/not-found", page: () => PageNotFound(), transition: Transition.noTransition),
              defaultTransition: Transition.native,
              // transitionDuration: Duration.zero,
              getPages: [
                GetPage(name: RootRoute, page: () => Root()),
                GetPage(name: AuthenticationPageRoute, page: () => AuthenticationPage()),
                GetPage(name: RegistrationPageRoute, page: () => RegistrationPage()),
                GetPage(name: ForgotPasswordPageRoute, page: () => ForgotPasswordPage()),
                GetPage(name: InvitePageRoute + "/:inviteId/:userId", page: () => InvitePage()),
                // GetPage(name: TrackPageRoute + "/:orderId", page: () => TrackPage())
              ],
              debugShowCheckedModeBanner: false,
              title: 'xyz.com',
              theme: ThemeData(
                hoverColor: Colors.transparent,
                  splashColor: Colors.transparent,
                  // highlightColor: Colors.transparent,
                  primarySwatch: Colors.blue,
                  scaffoldBackgroundColor: light,
                  // scaffoldBackgroundColor: Colors.white,
                  textTheme: GoogleFonts.mulishTextTheme(
                      Theme.of(context).textTheme).apply(
                      bodyColor: Colors.black
                  ),
                  pageTransitionsTheme: PageTransitionsTheme(builders: {
                    TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
                    TargetPlatform.android: FadeUpwardsPageTransitionsBuilder()
                  })
              )
          );

提前致谢。有什么想问的都可以问。

您的代码绝对没问题,可以正常工作。我试过了,但无法重现。

但是,您需要访问 xyz.com/#/invite/dd/dd 而不是 xyz.com/invite/dd/dd。 访问 xyz.com/invite/dd/dd 将重定向到初始路由。

要从URL中删除#,请参考this