Skip to main content
Cinemapedia uses GoRouter for declarative, URL-based navigation. All routes are defined in a single appRouter instance and wired into MaterialApp.router.

Router setup

lib/config/router/app_router.dart

initialLocation

The router opens on / (the home screen) when the app launches. Change initialLocation to send users to a different screen on first load.

Configured routes

Nested routes

The movie detail route is declared as a child of the home route, not as a top-level entry:
Nesting routes under a parent lets GoRouter compose the full URL path automatically. The resulting URLs are:
  • / — home
  • /movie/550 — detail page for movie with id 550
Child paths do not start with a leading /. GoRouter joins the parent path and the child path for you, so '/' + 'movie/:id' becomes /movie/:id.

Path parameters

The :id segment is a dynamic path parameter. GoRouter extracts it from the URL and makes it available via state.pathParameters:
If the parameter is absent for any reason, movieId falls back to 'no-id' so the build never receives a null value. Use the named-route helpers anywhere in the widget tree:
Prefer pushNamed / goNamed over string-based navigation. If a route name or path changes you only need to update the GoRoute declaration — all call sites that reference the name constant stay correct automatically.

Wiring the router to the app

The appRouter instance is passed to MaterialApp.router in main.dart:
lib/main.dart
Using MaterialApp.router instead of MaterialApp hands full navigation control to GoRouter, enabling deep linking and URL-driven navigation on web and mobile alike.