Repository: flutter
Issue: [go_router][go_router_builder] It will be executed twice redirect when putting the URL directly
Labels: platform-web,package,has reproducible steps,P2,p: go_router,p: go_router_builder,team-go_router,triaged-go_router,found in release: 3.24,found in release: 3.27

### Steps to reproduce

1. run it on broswer: chrome
  e.g. url is : `http://localhost:53306/`
2. put url in Put the url into the address bar. 
  e.g. `http://localhost:53306/login
3. It will run twice, then show root in page
  e.g. `http://localhost:53306/`

### Expected results

Still in Login page

### Actual results

wait late or click other window, It will go back to home page.

### Code sample

<details open><summary>main.dart</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:web_app/router.dart';
import 'package:flutter_web_plugins/url_strategy.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  usePathUrlStrategy();
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      routerConfig: GoRouter(
        navigatorKey: rootKey,
        debugLogDiagnostics: true,
        routes: $appRoutes,
        initialLocation: "/",
        redirect: (context, state) {
          print("_>___ app: get router.base path: ${Uri.base.path}/base: ${Uri.base}");
          print("__>__  app: get router.location: ${state.matchedLocation}");

          final uri = Uri.parse(state.matchedLocation);

          final paths = [ContentRouteData().location];
          if (paths.contains(uri.path)) {
            return LoginRouteData().location;
          }
          return null;
        },
        errorBuilder: (context, state) {
          // return ErrorRoute().build(context, state);
          return Container();
        },
        // refreshListenable: _appProvider,
      ),
    );
  }
}

class IndexPage extends StatelessWidget {
  final Widget child;

  const IndexPage({super.key, required this.child});

  @override
  Widget build(BuildContext context) {
    return child;
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            const Text("Home Page"),
            ElevatedButton(
              onPressed: () {
                context.go(ContentRouteData().location);
              },
              child: const Text("go content"),
            ),
          ],
        ),
      ),
    );
  }
}

class MemberPage extends StatelessWidget {
  const MemberPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: Text("Member Page"),
      ),
    );
  }
}

class ContentPage extends StatelessWidget {
  const ContentPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: Text("Content Page"),
      ),
    );
  }
}

class LoginPage extends StatelessWidget {
  const LoginPage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: Text("Login Page"),
      ),
    );
  }
}

```

</details>

<details open><summary>router.dart</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:web_app/main.dart';

part 'router.g.dart';

final rootKey = GlobalKey<NavigatorState>();
final shellKey = GlobalKey<NavigatorState>(debugLabel: "index");

@TypedShellRoute<IndexRouteData>(routes: [
  TypedGoRoute<HomeRouteData>(path: "/", routes: [
    // TypedGoRoute<LoginRouteData>(path: "login"),
  ]),
  TypedGoRoute<ContentRouteData>(path: "/content"),
])
class IndexRouteData extends ShellRouteData {
  static final GlobalKey<NavigatorState> $parentNavigatorKey = rootKey;
  static final GlobalKey<NavigatorState> $navigatorKey = shellKey;

  @override
  Page<Function> pageBuilder(BuildContext context, GoRouterState state, Widget navigator) {
    return NoTransitionPage(child: IndexPage(child: navigator));
  }
}

class HomeRouteData extends GoRouteData {
  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return const NoTransitionPage(
      child: HomePage(),
    );
  }
}

class ContentRouteData extends GoRouteData {
  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return const NoTransitionPage(
      child: ContentPage(),
    );
  }
}

@TypedGoRoute<LoginRouteData>(path: "/login")
class LoginRouteData extends GoRouteData {
  // static final GlobalKey<NavigatorState> $parentNavigatorKey = rootKey;

  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return const NoTransitionPage(
      child: LoginPage(),
    );
  }
}
```

</details>


<details open><summary>pubspec.yaml</summary>

```yaml
name: web_app
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ^3.5.3

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.8
  go_router: ^14.4.1


dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^4.0.0
  build_runner: ^2.4.11
  go_router_builder: ^2.7.0

flutter:
  uses-material-design: true
```

</details>

### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>


https://github.com/user-attachments/assets/bf04c873-a751-4005-8f10-573a7243bc41


</details>



### Logs

<details open><summary>Logs</summary>

```console
_>___ app: get router.base path: /login/base: http://localhost:53306/login
__>__  app: get router.location: /login
[GoRouter] Full paths for routes:
├─ (ShellRoute)
│ ├─/ (Widget)
│ └─/content (Widget)
└─/login (Widget)

[GoRouter] setting initial location /
_>___ app: get router.base path: /login/base: http://localhost:53306/login
__>__  app: get router.location: /
[GoRouter] Full paths for routes:
├─ (ShellRoute)
│ ├─/ (Widget)
│ └─/content (Widget)
└─/login (Widget)

[GoRouter] setting initial location /

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
flutter -v doctor
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.6.1 23G93 darwin-arm64, locale zh-Hant-TW)
    • Flutter version 3.24.3 on channel stable at /Users/mosil/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (8 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (5 available)
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 130.0.6723.92
```

</details>