Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[go_router]Popped Route Reappears When Pressing Browser Back Button #164969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
uttamkh opened this issue Mar 11, 2025 · 3 comments
Open

[go_router]Popped Route Reappears When Pressing Browser Back Button #164969

uttamkh opened this issue Mar 11, 2025 · 3 comments
Labels
found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team

Comments

@uttamkh
Copy link

uttamkh commented Mar 11, 2025

What package does this bug report belong to?

go_router

What target platforms are you seeing this bug on?

Web

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
[Paste file content here]

Steps to reproduce

  1. Navigate from Home → /dashboard using context.push('/dashboard').
  2. Navigate from /dashboard → /screen3 using context.push('/screen3').
  3. Press an "Exit" button on /screen3, which calls context.pop() to return to /dashboard.
  4. Now on /dashboard, press the browser back button.
  5. Instead of navigating back to Home, the browser navigates back to /screen3.

Expected results

After popping a route with context.pop(), pressing the browser back button should navigate to the previous page in the browser history (Home in this case), not restore the popped page (screen3).

Actual results

Even though the popped route (screen3) was removed from go_router's stack, pressing the browser's back button still navigates back to it. This indicates that go_router and the browser's history stack are out of sync.

Code sample

Code sample
import 'package:flutter/material.dart';

import 'package:go_router/go_router.dart';

void main() {
  runApp(MyApp());
}

final GoRouter _router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const HomePage(),
    ),
    GoRoute(
      path: '/screen2',
      builder: (context, state) => const Screen2(),
    ),
    GoRoute(
      path: '/screen3',
      builder: (context, state) => const Screen3(),
    ),
  ],
  debugLogDiagnostics: true,
);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Page')),
      body: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: ElevatedButton(
              onPressed: () {
                context.push('/screen2'); // Push Screen2 onto the stack
              },
              child: const Text('dashboard'),
            ),
          ),
          ElevatedButton(
            onPressed: () {
              context.push('/screen3'); // Push Screen2 onto the stack
            },
            child: const Text('Go to Screen 3'),
          ),
        ],
      ),
    );
  }
}

class Screen2 extends StatelessWidget {
  const Screen2({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('dashboard')),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: () {
                context.push('/screen3'); // Pop back to Home Page
              },
              child: const Text('screen 3'),
            ),
            ElevatedButton(
              onPressed: () {
                context.pop(); // Pop back to Home Page
              },
              child: const Text('Exit to Home Page'),
            ),
          ],
        ),
      ),
    );
  }
}

class Screen3 extends StatelessWidget {
  const Screen3({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('screen 3')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            context.pop(); // Pop back to Home Page
          },
          child: const Text('exit'),
        ),
      ),
    );
  }
}

Screenshots or Videos

Screen.Recording.2025-03-11.at.6.01.27.PM.mov
Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.3, on macOS 15.3.1 24D70 darwin-arm64, locale
    en-IN)
    • Flutter version 3.27.3 on channel stable at
      /Applications/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (7 weeks ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    • Android SDK at /Users/uttamkinih/Library/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /Users/uttamkinih/.sdkman/candidates/java/current/bin/java
    • Java version OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build
      17.0.4.1+1)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.98.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.106.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   •
      macOS 15.3.1 24D70 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         •
      macOS 15.3.1 24D70 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript •
      Google Chrome 134.0.6998.45

[✓] Network resources
    • All expected network resources are available.
@maheshj01 maheshj01 added the in triage Presently being triaged by the triage team label Mar 11, 2025
@maheshj01
Copy link
Member

Reproducible on latest stable and the master channel, After popping the route it is still present in the browser history and can be navigated by pressing the browser back button

looks similar to #154759

flutter doctor -v
[!] Flutter (Channel stable, 3.29.1, on macOS 15.1.1 24B2091 darwin-arm64, locale en-US) [947ms]
    • Flutter version 3.29.1 on channel stable at /Users/mahesh/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 09de023485 (11 days ago), 2025-02-28 13:44:05 -0800
    • Engine revision 871f65ac1b
    • Dart version 3.7.0
    • DevTools version 2.42.2
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.1s]
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0) [1,620ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [143ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [142ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1) [141ms]
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.96.2) [22ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (4 available) [6.9s]
    • sdk gphone16k arm64 (mobile)    • emulator-5554         • android-arm64  • Android 15 (API 35) (emulator)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.1.1 24B2091 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.1.1 24B2091 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources [777ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 3.30.0-1.0.pre.330, on macOS 15.1.1 24B2091 darwin-arm64, locale en-US) [2.7s]
    • Flutter version 3.30.0-1.0.pre.330 on channel master at /Users/mahesh/Development/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 99e1a0652c (2 weeks ago), 2025-02-25 16:59:54 -0800
    • Engine revision 99e1a0652c
    • Dart version 3.8.0 (build 3.8.0-133.0.dev)
    • DevTools version 2.43.0

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,912ms]
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0) [1,186ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [139ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [139ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1) [137ms]
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.96.2) [20ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (3 available) [6.6s]
    • sdk gphone16k arm64 (mobile) • emulator-5554 • android-arm64  • Android 15 (API 35) (emulator)
    • macOS (desktop)              • macos         • darwin-arm64   • macOS 15.1.1 24B2091 darwin-arm64
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources [282ms]
    • All expected network resources are available.

• No issues found!

@maheshj01 maheshj01 added package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package team-go_router Owned by Go Router team found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 and removed in triage Presently being triaged by the triage team labels Mar 12, 2025
@maheshj01 maheshj01 changed the title Popped Route Reappears When Pressing Browser Back Button [go_router]Popped Route Reappears When Pressing Browser Back Button Mar 12, 2025
@maheshj01 maheshj01 added the platform-web Web applications specifically label Mar 12, 2025
@chunhtai chunhtai added triaged-go_router Triaged by Go Router team P2 Important issues not at the top of the work list labels Mar 13, 2025
@uttamkh
Copy link
Author

uttamkh commented Mar 18, 2025

Please can you help with any workaround or updates on this @chunhtai

@itsAkshatG13
Copy link

@uttamkh @maheshj01 @chunhtai
Any update here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-web Web applications specifically team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team
Projects
None yet
Development

No branches or pull requests

4 participants