In a browser, a destination has an address. Users expect Back, Forward, copied links and refresh to preserve that destination. Test these behaviors explicitly rather than only clicking through the app once.
Choose a URL strategy intentionally
The default hash strategy represents a route after #, such as /app/#/saved. The server receives the part before the hash. A path strategy uses /app/saved; a direct visit asks the server for that path before Flutter runs.
For path URLs, add the SDK dependency below to your existing pubspec.yaml, keeping the normal Flutter dependency:
dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
Call usePathUrlStrategy() before runApp in the web-enabled application:
import 'package:flutter_web_plugins/url_strategy.dart';
// Add to your existing main() before runApp(...):
usePathUrlStrategy();
This is a configuration fragment, not a complete main.dart. Your route parser or router still needs to map /saved to the correct screen. Changing URL strategy does not create a routing table.
Make the server and client agree
A path-based app needs a server fallback to its entry document for client routes. Existing assets must continue to resolve to their real files. Scope the fallback to the application’s own directory so a route such as /flutter-tutorial/ still reaches the static tutorial page.
The URL strategy guide documents the SDK setup. Continue with the shared-hosting deployment example for a scoped Apache rule and subfolder build.
Decide what belongs in the address
Put a shareable destination and stable filters in the URL. Avoid putting private access tokens or large serialized application state there. A local expanded panel can remain ephemeral; a product detail identifier usually belongs in the route.
Verification matrix
| Action | Expected result |
|---|---|
| Paste a nested URL into a new tab | Correct screen loads without visiting home first |
| Refresh that URL | Server returns the app entry point; client restores the route |
| Back and Forward | Prior destinations return predictably |
| Open a missing route | Deliberate not-found UI rather than an endless spinner |
| Request a real asset | Asset bytes are returned, not HTML |
Run these checks against the release output and actual server configuration. Development servers often supply a fallback automatically, so a successful local navigation is only part of the evidence.
Exercise
Add an optional search query to a lesson list. Copy the URL into a clean browser session and confirm it restores the filter. Distinguish a browser refresh failure from an API authorization failure in your notes.