[go_router] Navigating back does not update router location since `go_router` 5.2.0

This issue has been created since 2022-11-23.

Just switched to go_router 5.2.0 from 5.1.9

My app is using ShellRoute and GoRoute with only builder: (no pageBuilder:)

The problem I face is that, after upgrading to 5.2.0, the getter locationfrom my GoRouterinstances does not update after navigating back from a child page.

To navigate back, I either:

GoRouter.of(context).pop();

or

Navigator.of(context).pop();

To get the current location:

final router = GoRouter.of(context);
final currentLocation = router.location;

I get different errors in my project related to navigation with this issue since I use the current location to navigate in my app.

Logs
╰─ flutter analyze
Analyzing mobile...
No issues found! (ran in 2.9s)
╰─ flutter doctor -v
[✓] Flutter (Channel stable, 3.3.8, on macOS 13.0 22A380 darwin-arm, locale en-FR)
    • Flutter version 3.3.8 on channel stable at xxxxxxxxxxxxxxxxxxxxxxxxxx
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (2 weeks ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at xxxxxxxxxxxxxxxxxxxxxxxxxx
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.3)
    • 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 11.0.13+0-b1751.21-8125866)

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

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 067BF70E-951D-4615-BD8A-11DF75B16A74 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
ndelanou wrote this answer on 2022-11-23

Also tried to get the current location by using GoRouterState.of(context).location but I got errors since I'm only using GoRoute param builder: in my app.

danagbemava-nc wrote this answer on 2022-11-23

Hi @ndelanou,

Please provide a minimal complete reproducible code sample so that we can investigate this issue.

Thank you

conghaonet wrote this answer on 2022-11-23

I had the same problem.

Code Example:

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';


void main() => runApp(const MyApp());

/// The route configuration.
final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return const HomeScreen();
      },
      routes: <RouteBase>[
        GoRoute(
          path: 'details',
          builder: (BuildContext context, GoRouterState state) {
            return const DetailsScreen();
          },
        ),
      ],
    ),
  ],
);

/// The main app.
class MyApp extends StatelessWidget {
  /// Constructs a [MyApp]
  const MyApp({Key? key}) : super(key: key);

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

/// The home screen
class HomeScreen extends StatelessWidget {
  /// Constructs a [HomeScreen]
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: () => context.go('/details'),
              child: const Text('Go to the Details screen'),
            ),
          ],
        ),
      ),
    );
  }
}

/// The details screen
class DetailsScreen extends StatelessWidget {
  /// Constructs a [DetailsScreen]
  const DetailsScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details Screen')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <ElevatedButton>[
            ElevatedButton(
              onPressed: () => context.pop(),
              child: const Text('Go back to the Home screen'),
            ),
          ],
        ),
      ),
    );
  }
}
bit-void wrote this answer on 2022-11-23

I'm seeing this issue with 5.1.9 and 5.2.0. With ShellRoute with nested children set up like this:

  final _router = GoRouter(
    initialLocation: "/plants",
    routes: [
      ShellRoute(
        builder: (context, state, child) {
          return AppScaffold(
            child: child,
          );
        },
        routes: <RouteBase>[
          GoRoute(
            path: '/plants',
            pageBuilder: (context, state) =>
                const NoTransitionPage(child: ExploreTab()),
            routes: [
              GoRoute(
                path: ":id",
                builder: (context, state) {
                  return PlantScreen(id: state.params["id"]!);
                },
              )
            ],
          ),
          GoRoute(
            path: '/garden',
            pageBuilder: (context, state) =>
                const NoTransitionPage(child: GardenTab()),
            routes: [
              GoRoute(
                path: ":id",
                builder: (context, state) {
                  return PlantScreen(id: state.params["id"]!);
                },
              )
            ],
          ),
        ],
      ),
    ],
  )

I end up unable to renavigate to to the same id if I go back and forth from a list view to a details view.

Here is a video showing this issue:

Screen.Recording.2022-11-23.at.3.00.11.PM.mov

And here is the full log:

Performing hot restart...
Syncing files to device iPhone 14 Pro Max...
Restarted application in 580ms.
[GoRouter] INFO: 2022-11-23 14:59:59.002560 Full paths for routes:

[GoRouter] INFO: 2022-11-23 14:59:59.007496 setting initial location /plants
[GoRouter] INFO: 2022-11-23 14:59:59.265585 Using MaterialApp configuration
flutter: initializing garden
[GoRouter] INFO: 2022-11-23 15:00:23.489184 going to /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
[GoRouter] INFO: 2022-11-23 15:00:24.618979 popping /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
[GoRouter] INFO: 2022-11-23 15:00:25.401664 going to /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
[GoRouter] INFO: 2022-11-23 15:00:26.184702 going to /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
[GoRouter] INFO: 2022-11-23 15:00:27.434981 going to /plants/3dc16cea-61f0-4bcc-8e04-1c6e252ca1d6
[GoRouter] INFO: 2022-11-23 15:00:28.786222 popping /plants/3dc16cea-61f0-4bcc-8e04-1c6e252ca1d6
[GoRouter] INFO: 2022-11-23 15:00:29.735863 going to /plants/3dc16cea-61f0-4bcc-8e04-1c6e252ca1d6
[GoRouter] INFO: 2022-11-23 15:00:30.468003 going to /plants/3dc16cea-61f0-4bcc-8e04-1c6e252ca1d6
[GoRouter] INFO: 2022-11-23 15:00:31.802194 going to /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
[GoRouter] INFO: 2022-11-23 15:00:32.805591 popping /plants/5544f692-5d74-46b1-b167-94e85cb7e95f
jauntybrain wrote this answer on 2022-11-24

I have the same issue, GoRouter 5.2.0. Are there any known solutions yet?

lukaszdebowski wrote this answer on 2022-11-24

This same issue also is present on the go_router package official example of the ShellRoute (examples/shell_route.dart) - navigating to a details page in TabA, then going back using the app bar back button, and navigating again to the details page on the same tab doesn't work. (also, the url is not updated after going back from the details screen)

danagbemava-nc wrote this answer on 2022-11-24

Reproducible using the code sample in #115913 (comment)
It is also reproducible using the shell_route example from the package examples.

This is likely a regression, although I'm not sure on which version the issue appeared.

Labeling for further investigation

recordings
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2022-11-24.at.09.40.26.mp4
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0.1 22A400 darwin-arm, locale en-GB)
    • Flutter version 3.3.9 on channel stable at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (2 days ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

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

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • 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 11.0.13+0-b1751.21-8125866)

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview 2.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/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 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/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 11.0.13+0-b1751.21-8125866)

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

[✓] Connected device (4 available)
    • Nexus (mobile)         • 00008020-001875E83A38002E            • ios            • iOS 16.1.1 20B101
    • iPhone 14 Pro (mobile) • 4F72110C-F38B-4CF9-93C4-4D6042148D28 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.6.0-7.0.pre.45, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
    • Flutter version 3.6.0-7.0.pre.45 on channel master at /Users/nexus/dev/sdks/flutters
    ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d0352f55db (9 hours ago), 2022-11-23 20:01:26 -0500
    • Engine revision 9b2895724c
    • Dart version 2.19.0 (build 2.19.0-424.0.dev)
    • DevTools version 2.19.0
    • 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 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

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

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • 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 11.0.13+0-b1751.21-8125866)

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview 2.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
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/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 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/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 11.0.13+0-b1751.21-8125866)

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

[✓] Connected device (4 available)
    • Nexus (mobile)         • 00008020-001875E83A38002E            • ios            • iOS 16.1.1 20B101
    • iPhone 14 Pro (mobile) • 4F72110C-F38B-4CF9-93C4-4D6042148D28 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.
mregandla wrote this answer on 2022-11-24

I did not see this issue in 4.5.1. But from 5.0.0, I see this.

vinay416 wrote this answer on 2022-11-24

I did not see this issue in 4.5.1. But from 5.0.0, I see this.

Yeah you are right I almost check all version above 5.0.0 and all have the issues. But In 4.5.1 there is no issue for me.

ValentinVignal wrote this answer on 2022-11-25

I think this is a duplicate of #115832

danagbemava-nc wrote this answer on 2022-11-25

Closing this in favor of #115832.

Kindly follow up in the issue linked above for updates.

Thank you

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Proper way to create PixiComponent in typescript 3 2021-11-02 2022-11-05
[PHP 8.1] Deprecated Optional parameter $url 1 2022-01-18 2022-11-29
Title: Love Calculator Android App using Rapid API 0 2022-04-18 2022-12-09
Top Level Directory not shown correctly on main menu 1 2022-04-24 2022-11-07
Support MySQL Key BTREE 0 2022-09-03 2022-11-19
vim8建议更换安装方式 2 2019-10-16 2022-01-09
Patche for react-reveal 0 2021-07-28 2022-11-29
False positive bitcanna.io 1 2022-05-04 2022-10-06
Default Sources: Energized Protection 1 2022-03-23 2022-10-27
Inheritance mapping issue with abstract class 2 2019-03-25 2022-12-02
Crash on flags "-a --self-check" 1 2022-10-10 2022-12-03
Import Emulator - Cemu Error 0 2022-06-04 2022-10-20
Build error In Visual Studio 2019 1 2022-04-12 2022-11-12
Colon in Label-text on special occasion 4 2022-03-16 2022-11-12
Snapshots and time series 2 2021-02-18 2022-11-05
Epic: enable fearless cooperation 2 2022-05-25 2022-12-02
程序能导出csv文件,但不运行将数据导入Mysql服务 3 2022-04-23 2022-12-02
gftools fix-fsselection doesn't work 7 2022-05-06 2022-11-25
Accept String variable as CiscoConfParse input 2 2022-07-19 2022-12-01
switch 国行游戏机 无法观看 腾讯视频 被屏蔽了 1 2021-11-28 2022-11-29
想问一下 一般用户是直接把 geoip.dat,geosite.dat 这两个文件下载替换了就可以了是吗? 2 2021-12-30 2022-11-29
Google Apple 域名使用 domain 匹配 10 2021-12-22 2022-11-29
Escape sequences in strings 6 2021-12-09 2022-01-09
[NTR] Add esophagus nonkeratinized squamous epithelial cell 1 2022-02-21 2022-11-14
i have this error when i use sublist3r.py 11 2020-10-06 2022-11-20
good way to record which specs have been re-tried? 4 2019-07-22 2022-10-03
Proposal: Subpackage to handle level-loading through .tmx files. 5 2020-06-27 2022-11-06
PHP Notice: Trying to access array offset on value of type resource 5 2022-07-19 2022-11-22
Deploying an stack with same service modifies the existing one 2 2022-06-29 2022-10-13
`:help popup-examples` needs more interesting examples 8 2022-05-18 2022-11-25
@emotion/core upgrade issue 1 2021-09-22 2022-12-03
Bug: When changing filter from Status to any other text contained property the `include` should change to `is` 0 2022-11-15 2022-11-30
Changing the language from Focus, opens the added shortcut 1 2022-04-05 2022-10-23
Prometheus: Variables with curly braces stopped working in 8.3.x 15 2021-12-08 2022-10-19
cron job stops after certain hours. 43 2016-05-15 2022-11-30
Using a secret to configure an EventSource (AMQP) 0 2021-06-01 2022-11-12
local.properties + require a higher Android SDK version 12 2022-07-01 2022-11-11
Build failure when private repos are omitted 2 2021-07-19 2022-11-11
"R2 get started guide" doesn't work as-written, steps are out of order? 1 2022-06-04 2022-11-23
团队不制作几个主流服务器系统的安装包吗 2 2017-09-30 2022-01-09
Translation optimization 2 2022-06-02 2022-12-01
show/download command should follow redirects 4 2022-10-16 2022-11-14
HTTP API uses redirects with 301 status, which leads to GET subsequent request in some clients 1 2021-07-20 2022-11-01
第二章 2.8.1 Dart单线程模型 1 2021-12-31 2022-01-12
Is it necessary to catch SIGSEGV when checking the HW bound? 2 2022-03-23 2022-10-27
MySQL MyISAM 0 2021-03-02 2022-01-16
When the node is abnormal, the output format of the Top node is incorrect 5 2021-09-16 2022-11-22
inline async function in v-on handler 0 2021-09-12 2022-12-08
How to solve "Invalid Emulator component" issue in Mobile Blazor Bindings 1 2021-11-14 2022-09-04
Flutter web cannot render high resolution images which are resolution aware 15 2022-08-07 2022-12-01