Repository: flutter
Issue: [go_router] exception on opening app by deeplink
Labels: c: crash,package,has reproducible steps,P2,p: go_router,found in release: 3.10,team-go_router,triaged-go_router,found in release: 3.13

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Assume that we have a sample Flutter app (com.example.app) which uses goRouter (for example sample from pub dev).
1. Open that app
2. Send app to background
3. Open app using deeplink `yoursScheme://com.example.app`



### Expected results

App is brought from background to front on the same screen that we left it without exception.

### Actual results

App opens on the screen was left going into background but apps throws exception.

Note
When app opened with `yoursScheme://com.example.app/` app goes to home screen configured as "/", but use case is to just bring app from background without chaning the location.

### Code sample

<details><summary>Code sample</summary>

```dart
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// This sample app shows an app with two screens.
///
/// The first route '/' is mapped to [HomeScreen], and the second route
/// '/details' is mapped to [DetailsScreen].
///
/// The buttons use context.go() to navigate to each destination. On mobile
/// devices, each destination is deep-linkable and on the web, can be navigated
/// to using the address bar.
void main() => runApp(const MyApp());

/// The route configuration.
final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return const HomeScreen();
      },
      routes: <RouteBase>[
        GoRoute(
          path: 'details',
          builder: (BuildContext context, GoRouterState state) {
            return const DetailsScreen();
          },
        ),
      ],
    ),
  ],
);

/// The main app.
class MyApp extends StatelessWidget {
  /// Constructs a [MyApp]
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

/// The home screen
class HomeScreen extends StatelessWidget {
  /// Constructs a [HomeScreen]
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.go('/details'),
          child: const Text('Go to the Details screen'),
        ),
      ),
    );
  }
}

/// The details screen
class DetailsScreen extends StatelessWidget {
  /// Constructs a [DetailsScreen]
  const DetailsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => context.go('/'),
          child: const Text('Go back to the Home screen'),
        ),
      ),
    );
  }
}
```
Sample from pub dev
</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details><summary>Logs</summary>

```console
10.10.0 - [FirebaseAnalytics][I-ACS023000] Deep Link Web URL query is empty
flutter: ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞═════════════════════
flutter: The following RangeError was thrown while dispatching
flutter: notifications for GoRouteInformationProvider:
flutter: RangeError (startIndex): Invalid value: Only valid value is 0: 1
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      RangeError.checkValueInInterval (dart:core/errors.dart:313:7)
flutter: #1      _StringBase.replaceFirst (dart:core-patch/string_patch.dart:591:16)
flutter: #2      canonicalUri (package:go_router/src/path_utils.dart:136:17)
flutter: #3      RouteConfiguration.findMatch (package:go_router/src/configuration.dart:271:31)
flutter: #4      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:86:23)
flutter: #5      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:705:8)
flutter: #6      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:723:5)
flutter: #7      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:403:24)
flutter: #8      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:141:11)
flutter: #9      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:236:5)
flutter: #10     GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:267:5)
flutter: #11     WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:685:24)
flutter: <asynchronous suspension>
flutter: #12     MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:547:42)
flutter: <asynchronous suspension>
flutter: #13     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:479:22)
flutter: <asynchronous suspension>
flutter:
flutter: The GoRouteInformationProvider sending notification was:
flutter:   Instance of 'GoRouteInformationProvider'
flutter: ═════════════════════════════════════════════════════════════════
flutter: while dispatching notifications for GoRouteInformationProvider: ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞═════════════════════
flutter: The following RangeError was thrown while dispatching
flutter: notifications for GoRouteInformationProvider:
flutter: RangeError (startIndex): Invalid value: Only valid value is 0: 1
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      RangeError.checkValueInInterval (dart:core/errors.dart:313:7)
flutter: #1      _StringBase.replaceFirst (dart:core-patch/string_patch.dart:591:16)
flutter: #2      canonicalUri (package:go_router/src/path_utils.dart:136:17)
flutter: #3      RouteConfiguration.findMatch (package:go_router/src/configuration.dart:271:31)
flutter: #4      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:86:23)
flutter: #5      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:705:8)
flutter: #6      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:723:5)
flutter: #7      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:403:24)
flutter: #8      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:141:11)
flutter: #9      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:236:5)
flutter: #10     GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:267:5)
flutter: #11     WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:685:24)
flutter: <asynchronous suspension>
flutter: #12     MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:547:42)
flutter: <asynchronous suspension>
flutter: #13     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:479:22)
flutter: <asynchronous suspension>
flutter:
flutter: The GoRouteInformationProvider sending notification was:
flutter:   Instance of 'GoRouteInformationProvider'
flutter: ═════════════════════════════════════════════════════════════════
flutter: RangeError (startIndex): Invalid value: Only valid value is 0: 1
flutter: #0      RangeError.checkValueInInterval (dart:core/errors.dart:313:7)
flutter: #1      _StringBase.replaceFirst (dart:core-patch/string_patch.dart:591:16)
flutter: #2      canonicalUri (package:go_router/src/path_utils.dart:136:17)
flutter: #3      RouteConfiguration.findMatch (package:go_router/src/configuration.dart:271:31)
flutter: #4      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:86:23)
flutter: #5      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:705:8)
flutter: #6      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:723:5)
flutter: #7      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:403:24)
flutter: #8      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:141:11)
flutter: #9      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:236:5)
flutter: #10     GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:267:5)
flutter: #11     WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:685:24)
flutter: <asynchronous suspension>
flutter: #12     MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:547:42)
flutter: <asynchronous suspension>
flutter: #13     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:479:22)
flutter: <asynchronous suspension>
flutter:

======== Exception caught by foundation library ====================================================
The following RangeError was thrown while dispatching notifications for GoRouteInformationProvider:
RangeError (startIndex): Invalid value: Only valid value is 0: 1

When the exception was thrown, this was the stack: 
#0      RangeError.checkValueInInterval (dart:core/errors.dart:313:7)
#1      _StringBase.replaceFirst (dart:core-patch/string_patch.dart:591:16)
#2      canonicalUri (package:go_router/src/path_utils.dart:136:17)
#3      RouteConfiguration.findMatch (package:go_router/src/configuration.dart:271:31)
#4      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:86:23)
#5      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:705:8)
#6      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:723:5)
#7      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:403:24)
#8      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:141:11)
#9      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:236:5)
#10     GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:267:5)
#11     WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:685:24)
<asynchronous suspension>
#12     MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:547:42)
<asynchronous suspension>
#13     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:479:22)
<asynchronous suspension>
The GoRouteInformationProvider sending notification was: Instance of 'GoRouteInformationProvider'
====================================================================================================
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[!] Flutter (Channel stable, 3.10.6, on macOS 13.3.1 22E772610a darwin-x64, locale pl-PL)
    • Flutter version 3.10.6 on channel stable at /Users/mateuszdudkowski/fvm/versions/3.10.6
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/2.18.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/mateuszdudkowski/fvm/versions/3.10.6. Consider adding /Users/mateuszdudkowski/fvm/versions/3.10.6/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (4 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1
    • 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 34.0.0)
    • Android SDK at /Users/mateuszdudkowski/Library/Android/sdk
    • Platform android-33, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • 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.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2022.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] Connected device (3 available)
    • iPhone (Mateusz Dudkowski) (mobile) • ------------------ • ios            • iOS 16.5.1 20F75
    • macOS (desktop)                     • macos                     • darwin-x64     • macOS 13.3.1 22E772610a darwin-x64
    • Chrome (web)                        • chrome                    • web-javascript • Google Chrome 115.0.5790.170

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

```

</details>