Tutorials
Open a route from a URL and keep browser navigation working
Parent pages, old URLs, parameter validation, Back, Forward and browser reload.
This continues the account example in the same unpublished fixture. It is a full root-router replacement, not two simultaneous URI owners. The source apps use go_router 18.1.5 and auto_route 11.2.0; the target uses the published Ark Navigation 2.4.0. No runtime package change is required.
1. Start from a direct link, not from Home
From the repository checkout:
cd tool/migration/source_routers
flutter pub get
flutter test test/cold_link_migration_test.dart
The suite has 42 Widget checks, with identical expectations for all three routers. The complete tests supply an initial URI to the actual root app. They do not call a hidden push first.
| Initial URI | Required visible page and parents |
|---|---|
| /browse/products/sku-42 | Product; Select returns to Catalog, Back then reaches Home |
| /item/sku-42 | Same guest Product, canonical address /browse/products/sku-42 |
| /browse | Catalog with relevance sorting, the explicit absent-query default |
| /browse?sort=price | Catalog with price sorting |
| /account/catalog/products/sku-42 | When signed in: Account Shell containing Catalog → Product |
| /account/profile | When signed in: Account Shell with Profile selected |
| Private URL while signed out | Sign in; cancellation returns to Home, not a private page |
Cold Product has no suspended caller waiting on push. Selecting it removes Product but leaves Catalog at No selection; SelectionRecorder stays empty. That is different from opening Product interactively and awaiting its result.
2. Give each root the actual initial URI
MigrationApp reads the platform's initial route when no test override is provided. It owns access state and validates the application input before creating a router.
GoSourceApp passes the explicit initialLocation and overridePlatformDefaultLocation to its single GoRouter. Its guest route hierarchy supplies Home → Catalog → Product. The host's /item/:productId redirect selects the generated GoProductRoute location.
AutoSourceApp uses includePrefixMatches and a one-time initial DeepLink.path override. Later browser route-information events are not replaced with the launch URI. AutoAppRouter declares the prefix routes and RedirectRoute for the short link; the Account Catalog tab has a nested AutoRouter.
ArkTargetApp explicitly supplies initialUri to NavigationSession. Session's existing default remains /; this fixture does not change the package default. While signed out, the host selects a local typed Sign-in target rather than trying to restore a forbidden child stack and leaving a partial private Shell.
3. Separate feature parents from application parents
The Catalog Module knows its local Catalog → Product plan. It does not know whether its host is guest or Account. The local targets do not hardcode the guest Mount: the URI compiler places them in the resolved Mount.
The guest Mount adds Home. The private Catalog Mount adds Home and Account before that same local plan. In PickerGraph:
uriParentPlan: NavigationUriParentPlan.fixed(
const <NavigationTarget<Object?>>[
NavigationTarget<void>(destination: HomeDestination()),
NavigationTarget<void>(destination: AccountDestination()),
],
),
HomeDestination and AccountDestination are the host-owned root entries. Catalog and Product remain in their own private Scope. The Profile Mount adds an Account configured for Profile. These are application-owned parents, not a request for the Catalog Module to depend on the Account UI.
ArkAccountScreen initializes only missing branches and restores the already selected branch after doing so. It must not push a fresh Catalog above a Product that URI restoration has already created. Initialization uses replacement history, not additional browser visits for every internal setup operation.
The root /item link is a host short-link redirect: ShortProductDestination and ShortProductRedirect. It redirects to the explicitly selected guest Mount and the canonical Product Destination; it is not another product page or an external return URL.
4. Reject invalid input visibly
MigrationLink applies shared application rules at startup: local known paths, nonblank product ID, allowed query values, no repeated parameters and a closed sign-in return-target list. These are host input checks, not evidence that three router decoders have identical error APIs. Routes still perform their own matching; Product constructors also validate IDs.
CatalogSort is an enum in the business-facing page and Ark/Go route declarations. An absent sort defaults to relevance; empty, unknown or repeated sort is rejected rather than silently defaulted. auto_route_generator 10.6.0 exposes the query value as a String; AutoCatalogScreen converts it through CatalogSort.parse before passing typed data to the page. The example does not pretend its source generator supports enum URI decoding.
Invalid input shows Invalid link and an Open home action. The tests use blank IDs, missing ID, empty/unknown/repeated sort, an external-looking return target and an unknown route. No private page or arbitrary product is substituted.
5. Run the browser check in CI
The separate source_router_web_build job builds all three Web apps. The source_router_web job uses pinned Playwright and Chromium in a pinned container. Its browser driver checks:
- Cold short link becomes the canonical Product address.
- Select after a cold link returns to Catalog without inventing a selection.
- Home → price-sorted Catalog → Product updates the address.
- Real browser Back and Forward change both the address and visible page.
- Reload at Product rebuilds its Catalog parent.
- Cold private Product renders Account; Profile → Catalog preserves Product, and browser Back/Forward revisits those private tabs and their addresses.
- Reload of private Product does not overwrite it during Shell initialization.
- Logout from that cold private flow reaches Home.
- An invalid sort shows an error and can recover to Home.
The report and failure screenshots are CI artifacts retained for one day. The CI job owns browser installation and generated build output. Cold test launches change the document URL, not just the hash: a same-document hash change is a router event, not a fresh application startup. For the root only, an empty hash and #/ both mean /. Other route fragments are compared exactly; successful rendering is checked separately from the URL.
For manual inspection with an already installed Flutter SDK:
flutter run -d web-server --web-port 18743 --dart-define=MIGRATION_SOURCE=ark --dart-define=DEMO_SIGNED_IN=true
Open the server address printed by Flutter and append #/account/catalog/products/sku-42. Choose go-router or auto-route for the other source apps. DEMO_SIGNED_IN is only a compile-time seed for this local navigation demo. It is false by default, is not persisted, and is not authentication or a production bypass.
Hash URLs are intentional. The fixture explicitly enables go_router's optionURLReflectsImperativeAPIs for its deeplinkable push targets and restores the previous option on disposal. That option is not a recommendation for every go_router app. A matching URL alone does not prove a preserved pending Future; the separate account suite still checks the original caller.
Chromium checks do not certify Safari, Firefox, OS link delivery, native gestures, production authentication or all invalid route-information events after startup.