Repository: flutter
Issue: [go_router] [web] Refreshing on nested app loses current route (redirect to initialLocation route)
Labels: platform-web,package,P2,p: go_router,team-go_router,triaged-go_router

## Context
The problem occurs on chrome.

In the basic code samples, the widget that creates the `GoRouter` is always the first widget in the widget tree. 
```dart
// [App] creates the GoRouter as a final field
void main() => runApp(const App());
```
In that case, there is no issue when refreshing (F5) the app. We keep the current route.

In real app, it's hard to create the GoRouter in the first widget because it's common to nest it in other widgets. In that case, when the navigator is refreshing, we lost the current route and we are redirected to the `initialLocation` route.

As a workaround, we can use a top level declaration of GoRouter (oustide any class).

I haven't seen any documentation talking about this.

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->
1. Add go_router: ^5.1.2 in pubspec.yaml
2. Launch the code sample in debug mode from VSCode (Run and Debug or F5) targetting Chrome (web)
2. Click on the button `Go to page 2`
3. Refresh the navigator or `F5`

**Expected results:** <!-- what did you want to see? -->
The navigator refreshes and we keep the page 2 route.

**Actual results:** <!-- what did you see? -->
We are redirected to the `initialLocation`route.

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() => runApp(const NestedApp());

class NestedApp extends StatelessWidget {
  const NestedApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return App();
  }
}

/// The main app.
class App extends StatelessWidget {
  /// Creates an [App].
  App({Key? key}) : super(key: key);

  /// The title of the app.
  static const String title = 'GoRouter Example: Declarative Routes';

  @override
  Widget build(BuildContext context) => MaterialApp.router(
        routerConfig: _router,
        title: title,
      );

  final GoRouter _router = GoRouter(
    routes: <GoRoute>[
      GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) => const Page1Screen(),
        routes: <GoRoute>[
          GoRoute(
            path: 'page2',
            builder: (BuildContext context, GoRouterState state) => const Page2Screen(),
          ),
        ],
      ),
    ],
  );
}

/// The screen of the first page.
class Page1Screen extends StatelessWidget {
  /// Creates a [Page1Screen].
  const Page1Screen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text(App.title)),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: () => context.go('/page2'),
                child: const Text('Go to page 2'),
              ),
            ],
          ),
        ),
      );
}

/// The screen of the second page.
class Page2Screen extends StatelessWidget {
  /// Creates a [Page2Screen].
  const Page2Screen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(title: const Text(App.title)),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: () => context.go('/'),
                child: const Text('Go back to home page'),
              ),
            ],
          ),
        ),
      );
}
```

<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->

</details>

<details>
<summary>Video</summary>

https://user-images.githubusercontent.com/34095172/199695699-06690fed-822b-43bc-a56c-4fec6c1b12ad.mov

</details>

</details>

<details>
<summary>Config</summary>

```
[✓] Flutter (Channel stable, 3.3.3, on macOS 12.6 21G115 darwin-x64, locale fr-FR)
    • Flutter version 3.3.3 on channel stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18a827f393 (5 weeks ago), 2022-09-28 10:03:14 -0700
    • Engine revision 5c984c26eb
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Connected device
    • Chrome (web)  • chrome                    • web-javascript • Google Chrome 107.0.5304.87
```
</details>