Ad

Flutter GetX Routing Will Redirected To InitialRoute

I currently investigate the following problem: When I try to open the page the first time with link arguments like "xyz.com/invite/dd/dd" I will immediately directed to the initial route "/". When I do it in the same tab again it will work and redirect me to the given page "/invite/dd/dd".

Here the console log for the first try:

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.

The console log the second try in the same tab:

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

It all worked fine at the second try when the page is loaded one time before!

The Sourcecode from the GetMaterialAPP in main.dart:

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()
                  })
              )
          );

Thanks in advance. Feel free to ask anything.

Ad

Answer

Your code is absolutely OK and working without any issues. I tried but couldn't reproduce it.

However, you need to visit xyz.com/#/invite/dd/dd instead of xyz.com/invite/dd/dd. Visiting xyz.com/invite/dd/dd will redirect to the initial route.

To remove the # from the URL, please refer to this

Ad
source: stackoverflow.com
Ad