Web refresh resets GoRouter stack: canPop() always false after reload
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
On Flutter Web, after a browser refresh (F5), the GoRouter navigation stack is reset.
As a result, `GoRouter.of(context).canPop()` returns `false` even if the user previously navigated through multiple pages before the refresh.
This makes it impossible to implement an in‑app Back button that behaves consistently with the browser history after reload.
### Steps to Reproduce
1. Open the app in a browser.
2. Navigate from `/a` to `/b` using `context.push(...)`.
3. Press F5 (browser refresh) while on `/b`.
4. Call `GoRouter.of(context).canPop()` (or press an app back button based on it).
### Expected results
`canPop()` should reflect that there is a previous route (or at least offer a way to access browser history).
In-app back should allow returning to `/a` after refresh.
### Actual results
`canPop()` is `false` after refresh, because the internal navigator stack is rebuilt from the current URL only.
### Code sample
```dart
final _router = GoRouter(
routes: [
GoRoute(path: '/a', builder: (_, __) => const PageA()),
GoRoute(path: '/b', builder: (_, __) => const PageB()),
],
);
class PageB extends StatelessWidget {
@override
Widget build(BuildContext context) {
final canPop = GoRouter.of(context).canPop();
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: canPop ? () => context.pop() : null,
),
),
body: Text('canPop: $canPop'),
);
}
}
```
go_router: ^17.0.0
### Screenshots or Video
_No response_
### Logs
### Flutter Doctor output
Doctor output
```console
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.0, on macOS 15.7.3 24G419 darwin-arm64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc1)
[!] Xcode - develop for iOS and macOS (Xcode 26.1.1)
✗ Xcode end user license agreement not signed; open Xcode or run the command 'sudo xcodebuild -license'.
✗ Xcode requires additional components to be installed in order to run.
Launch Xcode and install additional required components when prompted or run:
sudo xcodebuild -runFirstLaunch
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being
used to invoke it.
This can usually be fixed by re-installing CocoaPods.
For re-installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.108.2)
[✓] VS Code (version 1.75.0)
[✓] VS Code (version 1.105.1)
[✓] Connected device (1 available)
[✓] Network resources
! Doctor found issues in 1 category.
```
Contributor guide
Research direction
No repository file or test is named. Start by reproducing the `/a` to `/b` refresh flow in a Flutter web app, then inspect the GoRouter navigation and browser-history behavior around `GoRouter.of(context).canPop()`; done means in-app back can return to `/a` after refreshing on `/b`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100