[go_router] 5.2.0 `push` doesn't update the URL anymore.

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

Steps to Reproduce

  1. Execute flutter run on the code sample (see "Code sample" section below)
  2. Click on the button "Settings" to push the settings page
  3. Notice the URL didn't change when using go_router 5.2.0

Expected results:

I expect the URL to change

Actual results:

The URL didn't change


The issue doesn't happen in the previous version (5.1.10) so I believe this was introduced in flutter/packages#2786

I don't know if this is related to #99112 (comment) which plans to remove imperative methods. But since I didn't see anything in the changelogs or documentation, I'm assuming this is a regression.

Code sample

Or you can checkout https://github.com/ValentinVignal/flutter_app_stable/tree/go-router/push-no-url-change

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

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

final router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const Home(),
    ),
    GoRoute(
      path: '/settings',
      builder: (context, state) => const Settings(),
    ),
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Home'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            router.push('/settings');
          },
          child: const Text('Settings'),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Settings'),
      ),
    );
  }
}
Logs
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             25.8s
This app is linked to the debug service: ws://127.0.0.1:51507/t8SpI7d7848=/ws
Debug service listening on ws://127.0.0.1:51507/t8SpI7d7848=/ws

💪 Running with sound null safety 💪

🔥  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".

An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:51507/t8SpI7d7848=
Flutter Web Bootstrap: Auto
The Flutter DevTools debugger and profiler on Chrome is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:51507/t8SpI7d7848=
Analyzing flutter_app_stable...                                         
No issues found! (ran in 4.1s)
[✓] Flutter (Channel stable, 3.3.8, on macOS 11.6.8 20G730 darwin-x64, locale en-GB)
    • Flutter version 3.3.8 on channel stable at /Users/valentin/flutter/flutter
    • 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 30.0.3)
    • Android SDK at /usr/local/Caskroom/android-sdk/4333796
    • Platform android-33, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2021.1)
    • 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.11+0-b60-7590822)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 11.6.8 20G730 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.110

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

• No issues found!
Videos
5.2.0 5.1.10
Screen.Recording.2022-11-24.at.10.20.44.AM.mov
Screen.Recording.2022-11-24.at.10.17.18.AM.mov
exaby73 wrote this answer on 2022-11-24

Triage report

I can reproduce this issue. I can also confirm that the URL does indeed change in 5.1.10 but not in 5.2.0. Labeling as regression

Code Sample (Same as OP)
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

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

final router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const Home(),
    ),
    GoRoute(
      path: '/settings',
      builder: (context, state) => const Settings(),
    ),
  ],
);

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Home'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            router.push('/settings');
          },
          child: const Text('Settings'),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Settings'),
      ),
    );
  }
}
vinay416 wrote this answer on 2022-11-24

Yeah I'm facing the same issue when pushing the route URl is not updating. In mobile app using context.go going to the route but once I back to previous route then I can't longer go to same route again.

s9th wrote this answer on 2022-11-27

context.pop() also doesn't update URL. Maybe it's a consequence, maybe it's the same root cause.

tolo wrote this answer on 2022-11-29

It's related to the changes in RouteMatchList in 5.2.0. Previously, the location was calculated based on the RouteMatches, like this:

Uri get location =>
      _matches.isEmpty ? Uri() : Uri.parse(_matches.last.fullUriString);

But in 5.2.0, location was replaced with an uri field (final Uri uri) that is only set at the initial creation of the RouteMatchList, and never updated when pushing/popping.

tolo wrote this answer on 2022-11-29

Reading the discussion in #99112 I realise there are more complexity to consider, and I sort of understand the reasoning around that pushed routes perhaps doesn't justify a location change. However, I think pop is a bit different, since that operation is often performed indirectly via BackButtons etc (perhaps mostly mobile though, but perhaps not only), and it's performed for both pushed and "go:ed" routes. Perhaps the pop method in RouterDelegate needs to take into account if the last RouteMatch was an ImperativeRouteMatch or not, and apply different handling?

AceChen1 wrote this answer on 2022-12-05

@chunhtai may i know any status update or any schedule plan about this issue?

chunhtai wrote this answer on 2022-12-05

I plan to work on this soon.

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
Unable to write 3.34 to SFRKC30.AT3, version 3.25 works 1 2022-07-06 2022-10-02
NullPointerException in Kafka Connect 16 2021-05-27 2022-12-05
Certain links do not work anymore 1 2021-02-24 2022-05-18
Refactor `AbstractRepositoryBackend` with transaction/commit protocol 3 2022-03-15 2022-05-22
Python cannot be opened because of a problem 9 2021-03-15 2022-11-13
spec for `/send_join` response is contradictory 1 2022-02-03 2022-10-08
Logging in generates Bad API req 3 2017-01-04 2022-11-13
doesn't remove PY2 block if there's no `else` block 3 2021-11-10 2022-10-21
Login screen accessibility issues 0 2021-08-29 2022-11-13
Can't run on multiple localities with MPI 4 2020-10-06 2022-11-20
[FEATURE] Harvester supports event log 4 2022-09-07 2022-09-28
[FEATURE] Upgrade support of audit and event log 10 2022-09-07 2022-11-24
mac 11 big sur 失效 1 2020-10-10 2021-12-22
Zen mode is black 1 2020-10-07 2021-12-22
Handle Ctrl+C interupts for Mingw Executables 2 2021-03-15 2022-12-02
🚀 Feature Request: row-gap & column-gap for container 3 2022-08-08 2022-10-02
Feature requests: Better REPL error message? 1 2022-09-13 2022-10-05
Choose version when installing via url 0 2021-10-06 2022-12-02
Shoving away a chaplain traitor will not cancel them forcing you to sign a contract 1 2022-04-28 2022-11-20
Default gateway missing when multiple gateway are configured 7 2021-08-04 2022-11-15
[Bug][Docs]: Upgrading from v5 sidebar overlapping with content at horizontal scroll 1 2022-11-03 2022-11-28
[Feature]: continuing support for v5? (Due to deprecation of features in v6.) 1 2021-12-16 2022-11-03
OCSP check: Fix and re-enable CertChainTest.SendRequest 0 2021-03-06 2022-11-29
Collate existing practice in use of dct:conformsTo with DCAT 16 2020-03-10 2022-10-20
Disallow (writable) storage-buffers/textures in fragment shaders in core 14 2020-03-25 2022-11-12
zIndex set of appointment cell element is still behind all day event, Is there is any way to work around? 1 2022-01-04 2022-11-26
NGAlert - PagerDuty Notifier - Allow setting PD properties from alert data. 3 2022-05-03 2022-11-21
Epic: Search and browse dashboards 0 2022-05-04 2022-11-21
Fix S3927 FP: Support static abstract/virtual interface methods 1 2022-11-07 2022-11-21
Option to change cursorColor for showTextInputDialog() 2 2021-09-07 2022-11-14
On IOS devices, the first time you use the spring box, you get stuck 1 2021-03-18 2022-12-08
disable "ok" when input text is empty on showTextInputDialog. 2 2021-05-14 2022-11-18
Support for Synology DSM7 Structure 6 2020-12-13 2022-10-04
Security issues discovered 2 2021-06-07 2022-03-08
value-of<BackedEnum> would be cool to have 1 2022-03-09 2022-12-05
Error converting onnx to trtengine 2 2022-01-21 2022-10-31
Error Code 1: Serialization.. - When loading a serialized engine from file 3 2022-01-14 2022-10-31
Distributed: cannot use mutating member on immutable value, 'handler' is immutable 2 2022-05-30 2022-10-17
PaddleDetection2.4静态图版本多机多卡训练教程 5 2022-08-22 2022-11-10
golang如何把Tensor转换成图像? 3 2022-08-19 2022-10-22
请问Paddle的TransformerEncoder没有实现Position Encoding的功能吗 2 2022-08-22 2022-10-20
通过paddlex_restful新建检测训练任务或执行单张图像预测时,出现'cudaErrorInitializationError'偶发性错误。 5 2022-08-22 2022-10-18
python,inference不进行重新编译是否可以正常输出结果。 6 2022-08-22 2022-08-15
[Packaged App]`co_await` does't return to ui thread. when the call `PickSingleFolderAsync` is completed 3 2021-11-12 2022-10-02
Is dd-trace-java affected by the Log4j RCE exploit? 4 2021-12-10 2022-09-05
FT_Exception: (cannot open resource) 16 2022-07-12 2022-11-29
Very slow merge editor open 0 2022-10-18 2022-10-19
Git: Sync Changes Button Should Not Pull When There Are No Incoming Changes 0 2022-10-18 2022-10-19
Open ssl 3 and node repo server 1 2022-09-15 2022-11-21
hyperv: PermissionDenied: (:) [Start-VM], VirtualizationException 5 2021-09-22 2022-12-04