Skip to content

[go_router][Web] Navigating to the same current route doesn't work #171853

@glaceon2000

Description

@glaceon2000

Steps to reproduce

  1. Upgrade from 14.2.5 to any higher version
  2. Navigate to the same route as the current route

Expected results

The same route is pushed on stack and UI is reloaded

Actual results

Nothing happens. Page stays the same, buildPage not called

Code sample

main.dart
import 'package:flutter/material.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:go_router/go_router.dart';
import 'package:testing_textfield/router.dart';

void main() {
  GoRouter.optionURLReflectsImperativeAPIs = true;
  setUrlStrategy(PathUrlStrategy());
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final _router = GoRouter(
    initialLocation: '/',
    routes: $appRoutes,
    debugLogDiagnostics: true,
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'TESTING GO ROUTER',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        scaffoldBackgroundColor: const Color.fromARGB(255, 235, 235, 241),
      ),
      routeInformationParser: _router.routeInformationParser,
      routeInformationProvider: _router.routeInformationProvider,
      routerDelegate: _router.routerDelegate,
    );
  }
}
router.dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:testing_textfield/test_text_field.dart';

part 'router.g.dart';

@TypedGoRoute<HomeRouter>(path: '/')
class HomeRouter extends GoRouteData {
  const HomeRouter({this.text});
  final String? text;
  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    print('BUILDING PAGE!');
    return NoTransitionPage(
        child: Scaffold(
      backgroundColor: Colors.white,
      key: UniqueKey(),
      body: TestTextFieldScreen(text: text),
    ));
  }
}

router.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'router.dart';

// **************************************************************************
// GoRouterGenerator
// **************************************************************************

List<RouteBase> get $appRoutes => [
      $homeRouter,
    ];

RouteBase get $homeRouter => GoRouteData.$route(
      path: '/',
      factory: _$HomeRouter._fromState,
    );

mixin _$HomeRouter on GoRouteData {
  static HomeRouter _fromState(GoRouterState state) => HomeRouter(
        text: state.uri.queryParameters['text'],
      );

  HomeRouter get _self => this as HomeRouter;

  @override
  String get location => GoRouteData.$location(
        '/',
        queryParams: {
          if (_self.text != null) 'text': _self.text,
        },
      );

  @override
  void go(BuildContext context) => context.go(location);

  @override
  Future<T?> push<T>(BuildContext context) => context.push<T>(location);

  @override
  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);

  @override
  void replace(BuildContext context) => context.replace(location);
}
testing_text_field.dart
import 'package:flutter/material.dart';
import 'package:testing_textfield/router.dart';

class TestTextFieldScreen extends StatefulWidget {
  const TestTextFieldScreen({super.key, this.text});
  final String? text;

  @override
  State<TestTextFieldScreen> createState() => _TestTextFieldScreenState();
}

class _TestTextFieldScreenState extends State<TestTextFieldScreen> {
  final ctrl = TextEditingController();
  @override
  void dispose() {
    ctrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Column(
      children: [
        TextFormField(
          controller: ctrl,
        ),
        const SizedBox(height: 20),
        OutlinedButton(
            onPressed: () {
              const HomeRouter().go(context);
            },
            child: const Text('Refresh')),
      ],
    ));
  }
}

Screenshots or Video

Screenshots / Video demonstration
Screen.Recording.2025-07-09.at.15.15.22.mov

Logs

Logs
This application is not configured to build on the web.
To add web support to a project, run `flutter create .`.
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:52936/FNpLryfT5EM=/ws
Debug service listening on ws://127.0.0.1:52936/FNpLryfT5EM=/ws
Debug service listening on ws://127.0.0.1:52936/FNpLryfT5EM=/ws
BUILDING PAGE!
[GoRouter] Full paths for routes:
└─/ (Widget)

[GoRouter] setting initial location /
[GoRouter] going to /
[GoRouter] going to /
[GoRouter] going to /
[GoRouter] going to /
[GoRouter] going to /
[GoRouter] going to /
[GoRouter] going to /

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.24.3, on macOS 15.2 24C101 darwin-arm64,
    locale en-VN)
    ! Flutter version 3.24.3 on channel [user-branch] at /Users/mht/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions
      at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss
      this error.
    • Framework revision 2663184aa7 (10 months ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3
    • 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/mht/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
    ! CocoaPods 1.11.3 out of date (1.13.0 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see
      https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

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

[✓] Android Studio (version 2024.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
      17.0.11+0-17.0.11b1207.24-11852314)

[✓] Android Studio (version 2021.2)
    • Android Studio at /Volumes/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.12+0-b1504.28-7817840)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] VS Code (version 1.98.2)
    • VS Code at /Volumes/Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

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

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

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy