I'm navigating through go router in my web app. But I'm having issue while changing the screen is that when I open particular screen for the first time then its building whole screen with InitState() but after going to another screen, I'm clicking on that screen again then it's not rebuilding(means not running initState()). I've attached my code snippets as well.
final routerProvider = Provider<GoRouter>((ref) {
final loggedInState = ref.read(isLoggedInProvider);
return GoRouter(
refreshListenable: loggedInState,
routes: [
HomeRoute(), // /
PeopleRoute(), // /people
LoginRoute(),
],
redirect: (state) {
// if the user is not logged in, they need to login
final loggedIn = loggedInState.value;
final loggingIn = state.subloc == '/login';
if (!loggedIn) return loggingIn ? null : '/login';
// if the user is logged in but still on the login page, send them to
// the home page
if (loggingIn) return '/';
// no need to redirect at all
return null;
},
);
});
class HomeRoute extends GoRoute {
HomeRoute()
: super(
path: '/',
pageBuilder: (context, state) => const NoTransitionPage(
child: HomeScreen(),
),
);
}
class LoginRoute extends GoRoute {
LoginRoute()
: super(
path: '/login',
pageBuilder: (context, state) => const NoTransitionPage(
child: LoginScreen(),
),
);
}
class PeopleRoute extends GoRoute {
PeopleRoute()
: super(
path: '/people',
pageBuilder: (context, state) => const NoTransitionPage(
child: PeopleLandingScreen(),
),
);
}
Navigation Code.
context.go('/people');
Your help will be appreciated.