flutter-setup-declarative-routing
flutter/agent-plugins
Configure declarative routing in Flutter apps with go_router for deep linking and nested navigation.
What is flutter-setup-declarative-routing?
Set up go_router for URL-based navigation in Flutter web and mobile apps. Use this skill when you need advanced routing with deep linking support, browser history management, and persistent UI shells like bottom navigation bars.
- Configure GoRouter with path-based URL strategy for clean web URLs without hash fragments
- Implement nested navigation using StatefulShellRoute to maintain state across multiple navigation branches
- Set up platform-specific deep linking for Android (intent filters, assetlinks.json) and iOS (Info.plist, entitlements, apple-app-site-association)
- Create persistent UI shells like bottom navigation bars that wrap child routes
- Handle route parameters and implement error screens for invalid routes
- Support programmatic navigation with context.go() and context.push() methods
How to install flutter-setup-declarative-routing
npx skills add https://github.com/flutter/agent-plugins --skill flutter-setup-declarative-routing- Flutter SDK installed and a Flutter project created
- go_router package added to pubspec.yaml via flutter pub add go_router
- For web: flutter_web_plugins package for URL strategy configuration
- For deep linking: domain ownership and ability to host .well-known configuration files
How to use flutter-setup-declarative-routing
- 1.Run flutter pub add go_router to add the dependency
- 2.Call usePathUrlStrategy() in main() before runApp() to enable clean web URLs
- 3.Define a top-level GoRouter instance with your route tree using GoRoute and StatefulShellRoute
- 4.Bind the router to MaterialApp.router using the routerConfig parameter
- 5.For deep linking: configure platform-specific intent filters (Android) and entitlements (iOS)
- 6.Host assetlinks.json and apple-app-site-association files at your domain's .well-known directory
- 7.Test deep linking using adb shell for Android or xcrun simctl for iOS simulators
Use cases
- Building a Flutter web app with clean URLs and browser history support
- Creating a mobile app with deep linking that opens specific screens from external links
- Implementing a multi-tab app with bottom navigation that preserves each tab's navigation state
- Setting up authentication-based routing that redirects unauthenticated users to a login screen
- Configuring universal links for iOS or app links for Android to handle domain-based deep links
- Flutter developers building web applications
- Mobile app developers implementing deep linking
- Teams needing persistent navigation shells with multiple branches
- Developers migrating from imperative to declarative routing patterns
flutter-setup-declarative-routing FAQ
GoRoute maps a URL path to a single screen. StatefulShellRoute wraps multiple child routes in a persistent UI shell (like a bottom navigation bar) and maintains the navigation state of each branch independently.
No. Configure only the platforms you target. Android requires AndroidManifest.xml and assetlinks.json; iOS requires Info.plist, entitlements, and apple-app-site-association. Web works automatically with usePathUrlStrategy().
Use path parameters like 'details/:id' in the route path, then access them via state.pathParameters['id'] in the builder. Query parameters are available via state.uri.queryParameters.
It removes the '#' fragment from web URLs, enabling clean URLs like example.com/details/123 instead of example.com/#/details/123, which is essential for proper deep linking.
Use the redirect parameter in GoRouter to check authentication state and redirect unauthenticated users to a login route before building the requested screen.
Full instructions (SKILL.md)
Source of truth, from flutter/agent-plugins.
name: flutter-setup-declarative-routing
description: Configure MaterialApp.router using a package like go_router for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.
metadata:
model: models/gemini-3.1-pro-preview
last_modified: Tue, 21 Apr 2026 21:08:03 GMT
Implementing Routing and Deep Linking
Contents
- Core Concepts
- Workflow: Initializing the Application and Router
- Workflow: Configuring Platform Deep Linking
- Workflow: Implementing Nested Navigation
- Examples
Core Concepts
Use the go_router package for declarative routing in Flutter. It provides a robust API for complex routing scenarios, deep linking, and nested navigation.
- GoRouter: The central configuration object defining the application's route tree.
- GoRoute: A standard route mapping a URL path to a Flutter screen.
- ShellRoute / StatefulShellRoute: Wraps child routes in a persistent UI shell (e.g., a
BottomNavigationBar).StatefulShellRoutemaintains the state of parallel navigation branches. - Path URL Strategy: Removes the default
#fragment from web URLs, essential for clean deep linking across platforms.
Workflow: Initializing the Application and Router
Follow this workflow to bootstrap a new Flutter application with go_router and configure the root routing mechanism.
Task Progress
- Create the Flutter application.
- Add the
go_routerdependency. - Configure the URL strategy for web/deep linking.
- Implement the
GoRouterconfiguration. - Bind the router to
MaterialApp.router.
1. Scaffold the Application
Run the following commands to create the app and add the required routing package:
flutter create <app-name>
cd <app-name>
flutter pub add go_router
2. Configure the Router
Define a top-level GoRouter instance. Handle authentication or state-based routing using the redirect parameter.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
void main() {
// Use path URL strategy to remove the '#' from web URLs
usePathUrlStrategy();
runApp(const MyApp());
}
final GoRouter _router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomeScreen(),
routes: [
GoRoute(
path: 'details/:id',
builder: (context, state) => DetailsScreen(id: state.pathParameters['id']!),
),
],
),
],
errorBuilder: (context, state) => ErrorScreen(error: state.error),
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
title: 'Routing App',
);
}
}
Workflow: Configuring Platform Deep Linking
Configure the native platforms to intercept specific URLs and route them into the Flutter application.
Task Progress
- Determine target platforms (iOS, Android, or both).
- Apply conditional configuration for Android (Manifest + Asset Links).
- Apply conditional configuration for iOS (Plist + Entitlements + AASA).
- Run validator -> review errors -> fix.
If configuring for Android:
- Modify
AndroidManifest.xml: Add the intent filter inside the<activity>tag for.MainActivity.
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="yourdomain.com" />
<data android:scheme="https" />
</intent-filter>
- Host
assetlinks.json: Serve the following JSON athttps://yourdomain.com/.well-known/assetlinks.json.
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.yourcompany.yourapp",
"sha256_cert_fingerprints": ["YOUR_SHA256_FINGERPRINT"]
}
}]
If configuring for iOS:
- Modify
Info.plist: Opt-in to Flutter's default deep link handler. Note: If using a third-party deep linking plugin (e.g.,app_links), set this toNOto prevent conflicts.
<key>FlutterDeepLinkingEnabled</key>
<true/>
- Modify
Runner.entitlements: Add the associated domain.
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:yourdomain.com</string>
</array>
- Host
apple-app-site-association: Serve the following JSON (without a.jsonextension) athttps://yourdomain.com/.well-known/apple-app-site-association.
{
"applinks": {
"apps": [],
"details": [{
"appIDs": ["TEAM_ID.com.yourcompany.yourapp"],
"paths": ["*"],
"components": [{"/": "/*"}]
}]
}
}
Validation Loop
Run validator -> review errors -> fix.
- Android: Test using ADB.
adb shell 'am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://yourdomain.com/details/123"' com.yourcompany.yourapp - iOS: Test using
xcrunon a booted simulator.xcrun simctl openurl booted https://yourdomain.com/details/123
Workflow: Implementing Nested Navigation
Use StatefulShellRoute to implement persistent UI shells (like a bottom navigation bar) that maintain the state of their child routes.
Task Progress
- Define
StatefulShellRoute.indexedStackin theGoRouterconfiguration. - Create
StatefulShellBranchinstances for each navigation tab. - Implement the shell widget using
StatefulNavigationShell.
final GoRouter _router = GoRouter(
initialLocation: '/home',
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return ScaffoldWithNavBar(navigationShell: navigationShell);
},
branches: [
StatefulShellBranch(
routes: [
GoRoute(
path: '/home',
builder: (context, state) => const HomeScreen(),
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: '/settings',
builder: (context, state) => const SettingsScreen(),
),
],
),
],
),
],
);
Examples
High-Fidelity Shell Widget Implementation
Implement the UI shell that consumes the StatefulNavigationShell to handle branch switching.
class ScaffoldWithNavBar extends StatelessWidget {
const ScaffoldWithNavBar({
required this.navigationShell,
super.key,
});
final StatefulNavigationShell navigationShell;
void _goBranch(int index) {
navigationShell.goBranch(
index,
// Support navigating to the initial location when tapping the active tab.
initialLocation: index == navigationShell.currentIndex,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
bottomNavigationBar: NavigationBar(
selectedIndex: navigationShell.currentIndex,
onDestinationSelected: _goBranch,
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'),
],
),
);
}
}
Programmatic Navigation
Use the context.go() and context.push() extension methods provided by go_router.
// Replaces the current route stack with the target route (Declarative)
context.go('/details/123');
// Pushes the target route onto the existing stack (Imperative)
context.push('/details/123');
// Navigates using a named route and path parameters
context.goNamed('details', pathParameters: {'id': '123'});
// Pops the current route
context.pop();
Related skills
More from flutter/agent-plugins and the wider catalog.

flutter-setup-localization
Initialize Flutter localization with flutter_localizations, intl, and ARB file configuration.

flutter-testing-apps
Agent skill from flutter/agent-plugins.

flutter-theming-apps
Agent skill from flutter/agent-plugins.

flutter-use-http-package
Execute GET, POST, PUT, and DELETE requests in Flutter using the http package for REST API integration.

flutter-working-with-databases
Agent skill from flutter/agent-plugins.

flutter-accessibility
Configure Flutter apps for accessibility with screen readers, keyboard navigation, and adaptive layouts.