Repository: flutter
Issue: [go_router] On web redirect called but not executed when navigating with push
Labels: platform-web,package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.22,found in release: 3.23

### Steps to reproduce

1. Run `dart run build_runner build --delete-conflicting-outputs` to generate the routes.
2. Go to the authentication screen.
3. Press the `LoginButton`.
4. Press the browser's back arrow.
5. Press the browser's forward arrow.

### Expected results

Redirect to the `Home` screen.

### Actual results

Redirect is called, but no redirection occurs.

When navigating to the Login screen with a push and then moving forward using the browser's navigation arrows, the redirect is called but does not execute. However, if I access the Login screen using the button, the redirection works as expected.

As you can see, the redirect is called, but no redirection occurs:

![image](https://github.com/flutter/flutter/assets/124096434/e9fa19b2-00bf-459f-af94-2022daa03a0f)

### Code sample

<details open><summary>Code sample</summary>

```dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

part 'main.g.dart';

class LoginInfo extends ChangeNotifier {
  String _userName = '';
  String get userName => _userName;
  bool get loggedIn => _userName.isNotEmpty;

  void login(String userName) {
    _userName = userName;
    notifyListeners();
  }

  void logout() {
    _userName = '';
    notifyListeners();
  }
}

void main() => runApp(App());

final LoginInfo loginInfo = LoginInfo();

class App extends StatelessWidget {
  App({super.key});

  static const String title = 'GoRouter Example: Named Routes';

  @override
  Widget build(BuildContext context) => ChangeNotifierProvider<LoginInfo>.value(
        value: loginInfo,
        child: MaterialApp.router(
          routerConfig: _router,
          title: title,
          debugShowCheckedModeBanner: false,
        ),
      );

  late final GoRouter _router = GoRouter(
    debugLogDiagnostics: true,
    routes: $appRoutes,
    // changes on the listenable will cause the router to refresh it's route
    refreshListenable: loginInfo,
  );
}

@TypedGoRoute<HomeRoute>(
  path: '/',
  routes: [
    TypedGoRoute<LoginRoute>(
      path: 'login',
    )
  ],
)
class HomeRoute extends GoRouteData {
  const HomeRoute();

  @override
  Widget build(BuildContext context, GoRouterState state) => Scaffold(
        appBar: AppBar(
          title: const Text('Home Screen'),
          automaticallyImplyLeading: false,
          centerTitle: true,
        ),
        body: Center(
          child: TextButton(
              onPressed: () => context.push(const LoginRoute().location), // using go works as except
              child: const Text('Go to Auth')),
        ),
      );
}

class LoginRoute extends GoRouteData {
  const LoginRoute();

  @override
  FutureOr<String?> redirect(BuildContext context, GoRouterState state) {
    if (loginInfo.loggedIn) {
      return const HomeRoute().location;
    } else {
      return null;
    }
  }

  @override
  Widget build(BuildContext context, GoRouterState state) => Scaffold(
        appBar: AppBar(
          automaticallyImplyLeading: false,
          title: const Text('Login Screen'),
          centerTitle: true,
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () => context.read<LoginInfo>().login('test-user'),
            child: const Text('Login'),
          ),
        ),
      );
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

**Video:**

[Screencast from 28-05-24 10:19:37.webm](https://github.com/flutter/flutter/assets/124096434/122120b2-c680-403f-9e65-42aaec59375e)


</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.6, on Ubuntu 22.04.4 LTS 6.5.0-35-generic, locale en_US.UTF-8)
    • Flutter version 3.19.6 on channel stable at /home/user/fvm/versions/3.19.6
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (6 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /media/..../
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /home/user/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
    ✗ pkg-config is required for Linux development.
      It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from
      https://www.freedesktop.org/wiki/Software/pkg-config/

[✓] Android Studio (version 2023.3)
    • Android Studio at /home/andry/android-studio/
    • Flutter plugin version 79.0.2
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /home/user/android-studio/
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[!] Android Studio (version unknown)
    • Android Studio at /home/andry/android-studio
    • 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 determine Android Studio version.
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.89.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.88.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.4 LTS 6.5.0-35-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 125.0.6422.112

[✓] Network resources
    • All expected network resources are available.

```

</details>