Overview
Wonderous uses GoRouter for declarative routing and navigation. The routing system is defined inlib/router.dart and provides type-safe navigation, deep linking support, and a centralized route configuration.
ScreenPaths Class
TheScreenPaths class provides centralized path definitions for all routes in the application:
Dynamic Path Building
The_appendToCurrentPath method enables nested navigation by appending new paths to the current route:
Router Configuration
The main router is defined as aGoRouter instance:
ShellRoute Pattern
All routes are wrapped in aShellRoute that provides the WondersAppScaffold, ensuring consistent app structure across all screens.
Route Definitions
AppRoute Class
Wonderous uses a customAppRoute class that extends GoRoute to simplify route declarations:
- Automatic
Scaffoldwrapping - Optional fade transitions via
useFadeflag - Platform-appropriate page transitions (Cupertino vs Material)
- Support for nested routes
Main Routes
Reusable Route Definitions
Common routes are defined as getters for reuse across the route tree:Navigation Patterns
Programmatic Navigation
Full-Screen Dialogs
For modal overlays, Wonderous uses a custom dialog route method inAppLogic:
Redirect Logic
The router includes redirect logic to handle app initialization and deep linking:Deep Linking
Deep links are captured during app initialization and stored for later navigation:Parameter Parsing
Path Parameters
Query Parameters
Type-Safe Parsing
Error Handling
Unmatched routes display a custom error page:Best Practices
- Use ScreenPaths: Always use the
ScreenPathsclass for route paths to ensure type safety and consistency - Nested Routes: Use nested route definitions for logical grouping (e.g., all wonder-related routes under the wonder route)
- Query Parameters: Use query parameters for optional navigation state (e.g., tab index)
- Path Parameters: Use path parameters for required identifiers (e.g., artifact ID, wonder type)
- Reusable Routes: Define commonly-used routes (timeline, collection, artifact) as reusable getters
- Transitions: Use
useFade: truefor detail views to provide smooth transitions
Related Files
lib/router.dart- Main router configurationlib/logic/app_logic.dart- Bootstrap and navigation utilitieslib/ui/common/utils/page_routes.dart- Custom page route implementations