Repository: flutter
Issue: [go_router] Route triggered twice after navigating from 3rd party app by link (deep linking)
Labels: package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.13,found in release: 3.16

Hello.

I am currently working on implementing deep linking functionality in my application, which allows users to open the app via links received in emails. However, I have encountered an issue where the go_router behaves unexpectedly. Specifically, the route specified in go_router is triggered twice when the app is launched from a cold start. After the app has started, deep linking works as expected.

**Steps to reproduce:**
1. Run the Flutter project on an Android device.
2. Close the app using the back button on Android to ensure that the app is completely closed.
3. Open an email or any other app containing a deep link.
4. Click on the deep link to open the application.

**Expected Behavior:**
The specified widget should be created only once when the deep link is triggered, ensuring a single instance of the widget.

**Actual Behavior:**
The widget is created twice when the application is launched from a cold start on Android.

**Reproducibility:**
The issue consistently occurs when the application is launched from a cold start on Android. It does not occur when the application is already running.

I use go_router 12.0.0.

Example from https://github.com/flutter/codelabs/tree/main/deeplink_cookbook with minor changes:

Android manifest file:

```
<activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleInstance" // Added this mode to avoid issue with multiple activities

          ...........

            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="example.com" />
                <data android:scheme="https" />
</activity>
```

Dart code:

```
void main() => runApp(MaterialApp.router(routerConfig: router));

/// This handles '/' and '/details'.
final router = GoRouter(
  debugLogDiagnostics: kDebugMode,
  redirect: (context, state) {
    print('GoRouter redirect ${state.matchedLocation}');
    return null;
  },
  initialLocation: '/test',
  routes: [
    GoRoute(
      path: '/test',
      builder: (_, __) => Scaffold(
        appBar: AppBar(title: const Text('Home Screen')),
      ),
    ),
    GoRoute(
      path: '/details',
      builder: (_, __) {
        print('Open details screen');
        return Scaffold(
          appBar: AppBar(title: const Text('Details Screen')),
        );
      },
    ),
  ],
);

```

### Expected results

The route should be triggered once.

### Actual results

The route is triggered twice after the initial click on the link.

### Logs

<details><summary>Logs</summary>

```console
[GoRouter] setting initial location /test
I/flutter (32552): GoRouter redirect /details
[GoRouter] Using MaterialApp configuration
I/flutter (32552): Open details screen
I/flutter (32552): Open details screen
I/flutter (32552): GoRouter redirect /details
I/flutter (32552): Open details screen
I/flutter (32552): GoRouter redirect /details
I/flutter (32552): Open details screen
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.13.3, on macOS 12.6 21G115 darwin-x64, locale en-UA)
    • Flutter version 3.13.3 on channel stable at /Users/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2524052335 (7 weeks ago), 2023-09-06 14:32:31 -0700
    • Engine revision b8d35810e9
    • Dart version 3.1.1
    • DevTools version 2.25.0

⣟                                                                                                                                                                 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.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.15+0-b2043.56-8887301)

[✓] VS Code (version 1.81.1)
    • VS Code at /Users/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.72.0

[✓] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • macOS (desktop)         • macos         • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 118.0.5993.88

[✓] Network resources
    • All expected network resources are available.

• No issues found!

```

</details>