Repository: flutter
Issue: [go_router] GoRouter builds parent route when navigating directly to a subroute (deep link)
Labels: package,has reproducible steps,P3,p: go_router,team-go_router,triaged-go_router,found in release: 3.16,found in release: 3.19

### Steps to reproduce

**The Problem:** 
When using GoRouter to navigate directly to a subroute via a deep link, the parent route's build method is triggered. This results in an unnecessary and costly rebuild of the parent route's screen.

**Steps to Reproduce:**
1. Clone the code sample from [this Gist](https://gist.github.com/callmephil/d5c02c84a788fce17b682db0864074ff).
2. Create a new Flutter project with flutter create go_router_test and replace main.dart with the code from the Gist.
3. don't forget to add below **flutter:** in your dependencies. 
  ```
  flutter_web_plugins:
    sdk: flutter
  ```

4. Run the app in a browser.
5. Open the browser console and clear it.
6. Navigate to a subroute (e.g., www.localhost:PORT/1).
7. Observe that the parent route is built when navigating directly to its child.

Environment:
    (FVM) Flutter Version: 3.16.5
    GoRouter Version: 13.0.1

### Expected results

The parent route should not be built when navigating directly to a subroute.


### Actual results

The parent route is being built, which is unnecessary and causes performance issues.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:go_router/go_router.dart';

final _navKey = GlobalKey<NavigatorState>();

void main() {
  usePathUrlStrategy();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      routerConfig: GoRouter(
        navigatorKey: _navKey,
        debugLogDiagnostics: true,
        routerNeglect: true,
        initialLocation: '/',
        routes: [
          GoRoute(
            path: '/',
            builder: (context, state) {
              return const ParentScreen();
            },
            routes: [
              GoRoute(
                path: ':id',
                builder: (context, state) {
                  return const ChildScreen();
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class ParentScreen extends StatefulWidget {
  const ParentScreen({super.key});

  @override
  State<ParentScreen> createState() => _ParentScreenState();
}

class _ParentScreenState extends State<ParentScreen> {
  @override
  Widget build(BuildContext context) {
    // This print statement is being called if the child screen is opened.
    print('parent screen has been built');

    return Scaffold(
      appBar: AppBar(
        title: const Text('Parent Screen'),
      ),
      body: Center(
        child: TextButton(
          onPressed: () => context.go('/1'),
          child: const Text('Go to child screen'),
        ),
      ),
    );
  }
}

class ChildScreen extends StatelessWidget {
  const ChildScreen({super.key});

  @override
  Widget build(BuildContext context) {
    print('child screen has been built');
    return Scaffold(
      appBar: AppBar(
        title: const Text('Child Screen'),
      ),
      body: Center(
        child: TextButton(
          onPressed: () => context.go('/'),
          child: const Text('Go to parent screen'),
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/2213079/f5b8a179-e67c-4561-aadf-2bf39dfd3ec0

</details>


### Logs

<details open><summary>Logs</summary>

```console
flutter create go_router_deeplink_test
flutter pub add go_router
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    • Flutter version 3.16.5 on channel stable at /Users/phil/fvm/versions/3.16.5
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (3 weeks ago), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/phil/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/phil/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/phil/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.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2)
    • IntelliJ at /Users/phil/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 233.13135.65

[✓] VS Code (version 1.85.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 120.0.6099.199

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>