Skip to content

Commit 3488a31

Browse files
committed
docs(router): add comments explaining top-level routes and authentication handling
- Add detailed comments on router setup, auth handling, and top-level routes - Clarify the purpose and structure of global article details route - Explain the reasoning behind using a top-level route for article details - Update documentation on authentication route and app lifecycle integration
1 parent ee612c6 commit 3488a31

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

lib/router/router.dart

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ import 'package:go_router/go_router.dart';
5353
///
5454
/// Requires an [authStatusNotifier] to trigger route re-evaluation when
5555
/// authentication state changes.
56+
///
57+
///
58+
/// With the current App startup architecture, the router is only active
59+
/// when the app is in a stable, running state. The `redirect` function's
60+
/// only responsibility is to handle auth-based route protection.
61+
/// States like `configFetching`, `underMaintenance`, etc., are handled
62+
/// by the root App widget *before* this router is ever built.
63+
5664
GoRouter createRouter({
5765
required ValueNotifier<AppLifeCycleStatus> authStatusNotifier,
5866
required AuthRepository authenticationRepository,
@@ -161,13 +169,10 @@ GoRouter createRouter({
161169
// A neutral root route that the app starts on. The redirect logic will
162170
// immediately move the user to the correct location.
163171
GoRoute(path: '/', builder: (context, state) => const SizedBox.shrink()),
164-
// --- Simplified Authentication Route for New Users ---
165172
GoRoute(
166173
path: Routes.authentication,
167174
name: Routes.authenticationName,
168175
builder: (BuildContext context, GoRouterState state) {
169-
// This page is now self-contained and doesn't need parameters.
170-
// It's only for truly unauthenticated users.
171176
return BlocProvider(
172177
create: (context) => AuthenticationBloc(
173178
authenticationRepository: context.read<AuthRepository>(),
@@ -225,7 +230,11 @@ GoRouter createRouter({
225230
),
226231
],
227232
),
233+
228234
// --- Entity Details Route (Top Level) ---
235+
//
236+
// This route handles displaying details for various content entities
237+
// (Topic, Source, Country) based on path parameters.
229238
GoRoute(
230239
path: Routes.entityDetails,
231240
name: Routes.entityDetailsName,
@@ -278,7 +287,32 @@ GoRouter createRouter({
278287
);
279288
},
280289
),
290+
281291
// --- Global Article Details Route (Top Level) ---
292+
//
293+
// This GoRoute provides a top-level, globally accessible way to view the
294+
// HeadlineDetailsPage.
295+
//
296+
// Purpose:
297+
// It is specifically designed for navigating to article details from contexts
298+
// that are *outside* the main StatefulShellRoute's branches (e.g., from
299+
// EntityDetailsPage, which is itself a top-level route, or potentially
300+
// from other future top-level pages or deep links).
301+
//
302+
// Why it's necessary:
303+
// Attempting to push a route that is deeply nested within a specific shell
304+
// branch (like '/feed/article/:id') from a BuildContext outside of that
305+
// shell can lead to navigator context issues and assertion failures.
306+
// This global route avoids such problems by providing a clean, direct path
307+
// to the HeadlineDetailsPage.
308+
//
309+
// How it differs:
310+
// This route is distinct from the article detail routes nested within the
311+
// StatefulShellRoute branches (e.g., Routes.articleDetailsName under /feed,
312+
// Routes.searchArticleDetailsName under /search). Those nested routes are
313+
// intended for navigation *within* their respective shell branches,
314+
// preserving the shell's UI (like the bottom navigation bar).
315+
// This global route, being top-level, will typically cover the entire screen.
282316
GoRoute(
283317
path: Routes.globalArticleDetails,
284318
name: Routes.globalArticleDetailsName,

0 commit comments

Comments
 (0)