EV Guy
EV Guy

Reputation: 31

Router resets to app initial page when hitting the browser refresh button

Flutter versiom: 3.24.3 GoRouter version: 14.3.0 Browser: Chrome

I am using a shell route with the default hash strategy as follows (Partial route tree):

      ShellRoute(
        redirect: (BuildContext context, GoRouterState state) {
          if (!BlocProvider.of<AuthenticationBloc>(context).state.isAuthenticated) {
            return EvRoute.loginPage.path;
          }
          return null;
        },
        builder: (BuildContext context, GoRouterState state, Widget child) {
          return LogoutListener(
            authenticationBloc: BlocProvider.of<AuthenticationBloc>(context),
            child: MainPage(child: child),
          );
        },
        routes: [
          GoRoute(
            path: EvRoute.mainWrapperPage.path, - Path is /#/main
            name: EvRoute.mainWrapperPage.name,
            redirect: (context, state) => EvRoute.dashboardPage.path,
          ),
          GoRoute(
            path: EvRoute.dashboardPage.path, - path is /#/main/dashboard
            name: EvRoute.dashboardPage.name,
            builder: (context, state) => UserDashboardPage(),
          ),
          GoRoute(
            path: EvRoute.settingsPage.path, - path is /#/main/settings
            name: EvRoute.settingsPage.name,
            builder: (context, state) => SettingsPage(),
          ),
        ],
      ),

After navigating to the settings page (or any other page in the app other than the default) and then hitting chromes refresh button, instead of remaining on the /#/main/settings path it resets to the initial page which is /#/main (which in turn redirects to /#/main/dashboard.

This is not the intended behaviour when navigating any web app. On any web app the page remains in the current URL while maintaining the browser history.

Any help with this?

Upvotes: 1

Views: 68

Answers (1)

Tocklewo
Tocklewo

Reputation: 11

I think this happens because the refresh button calls the router.refresh();, so that the whole router object refreshes, and then the initialLocation is the top route in the app

Upvotes: 0

Related Questions