@@ -73,7 +73,10 @@ GoRouter createRouter({
7373
7474 return GoRouter (
7575 refreshListenable: authStatusNotifier,
76- initialLocation: Routes .feed,
76+ // Start at a neutral root path. The redirect logic will immediately
77+ // determine the correct path (/feed or /authentication), preventing
78+ // an attempt to build a complex page before the app state is ready.
79+ initialLocation: '/' ,
7780 debugLogDiagnostics: true ,
7881 // --- Redirect Logic ---
7982 redirect: (BuildContext context, GoRouterState state) {
@@ -87,6 +90,7 @@ GoRouter createRouter({
8790 );
8891
8992 // --- Define Key Paths ---
93+ const rootPath = '/' ;
9094 const authenticationPath = Routes .authentication;
9195 const feedPath = Routes .feed;
9296 final isGoingToAuth = currentLocation.startsWith (authenticationPath);
@@ -135,6 +139,12 @@ GoRouter createRouter({
135139 return feedPath;
136140 }
137141 }
142+
143+ // If the user is at the root path, they should be sent to the feed.
144+ if (currentLocation == rootPath) {
145+ print (' Action: User at root. Redirecting to feed.' );
146+ return feedPath;
147+ }
138148 }
139149
140150 // --- Fallback ---
@@ -144,6 +154,13 @@ GoRouter createRouter({
144154 },
145155 // --- Authentication Routes ---
146156 routes: [
157+ // A neutral root route that the app starts on. The redirect logic will
158+ // immediately move the user to the correct location. This route's
159+ // builder will never be called in practice.
160+ GoRoute (
161+ path: '/' ,
162+ builder: (context, state) => const SizedBox .shrink (),
163+ ),
147164 GoRoute (
148165 path: Routes .authentication,
149166 name: Routes .authenticationName,
0 commit comments