Repository: flutter
Issue: Flutter Web Nested Navigator issue while routing with URL...
Labels: framework,f: routes,platform-web,has reproducible steps,P2,found in release: 3.7,found in release: 3.11,team-web,triaged-web

Flutter version : 2.8.1
Hi all,

I am currently working on flutter web dev. which uses two navigator inside the app 
1. MaterialApp.
2. Navigator.

We are not facing the issue when do the navigation using links (Navigator Keys). But when we copy paste the same URL it is redirecting to random page and throwing the below exception. Both of the navigator used separate GlobalKey<NavigatorState>.

I have attached the sample code issue... 
**Main Route**

```
MaterialApp(
      title: 'Dockket web',
      onGenerateRoute: generateRoute,
      navigatorKey: Utils.mainAppNav,
      debugShowCheckedModeBanner: false,
      initialRoute: "/",
      onUnknownRoute: (settings) {
        _getPageRoute(Main3(), settings);
      },
      navigatorObservers: [NavigatorObserver()],
    );
  

Route<dynamic> generateRoute(RouteSettings settings) {
  print(settings.name);
  switch (settings.name) {
    case "/":
      return _getPageRoute(Main1(), settings);
    case "/m2":
      return _getPageRoute(Main2(), settings);
    case "/m3":
      return _getPageRoute(Main3(), settings);
    default:
      return _getPageRoute(Main1(), settings);
  }
}

PageRoute _getPageRoute(Widget child, RouteSettings settings) {
  return PageRouteBuilder(
      pageBuilder: (_, __, ___) => child,
      transitionDuration: const Duration(seconds: 0),
      settings: settings);
}
```
**Sub Route**
for Drawer navigation

```
 Navigator(
            reportsRouteUpdateToEngine: true,
            initialRoute: "/m3/file1",
            onGenerateRoute: generateRoute2,
            key: Utils.mainListNav,
          )
Route<dynamic> generateRoute2(RouteSettings settings) {
  switch (settings.name) {
    case "/m3/file1":
      return _getPageRoute2(FileOne(), settings);
    case "/m3/file2":
      return _getPageRoute2(FileTwo(), settings);
    case "/m3/file3":
      return _getPageRoute2(FileThree(), settings);
    case "/m3/file4":
      return _getPageRoute2(FileFour(), settings);
    default:
      return _getPageRoute2(FileFive(), settings);
  }
}

PageRoute _getPageRoute2(Widget child, RouteSettings settings) {
  return PageRouteBuilder(
      pageBuilder: (_, __, ___) => child,
      transitionDuration: const Duration(seconds: 0),
      settings: settings);
}
```

**Exception :**

```
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Duplicate GlobalKey detected in widget tree.
The following GlobalKey was specified multiple times in the widget tree. This will lead to parts of
the widget tree being truncated unexpectedly, because the second time a key is seen, the previous
instance is moved to the new location. The key was:
- [LabeledGlobalKey<NavigatorState>#8b6ff rr]
This was determined by noticing that after the widget with the above global key was moved out of its
previous parent, that previous parent never updated during this frame, meaning that it either did
not update at all or updated before the widget was moved, in either case implying that it still
thinks that it should have a child with that global key.
The specific parent that did not update after having one or more children forcibly removed due to
GlobalKey reparenting is:
- Expanded(flex: 1)
A GlobalKey can only be specified on one widget at a time in the widget tree.

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
packages/flutter/src/widgets/framework.dart 2897:15                           <fn>
packages/flutter/src/widgets/framework.dart 2921:16                           finalizeTree
packages/flutter/src/widgets/binding.dart 884:7                               drawFrame
packages/flutter/src/rendering/binding.dart 363:5                             [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1145:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1082:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 996:5                             [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1005:13                           invoke
lib/_engine/engine/platform_dispatcher.dart 159:5                             invokeOnDrawFrame
lib/_engine/engine.dart 455:45                                                <fn>
════════════════════════════════════════════════════════════════════════════════════════════════════
```



**flutter doctor -v**

```
(base) gopisekaran@gopis-MacBook-Air nav % flutter doctor -v
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.4 21F79 darwin-arm, locale en-IN)
    • Flutter version 2.8.1 at /Users/gopisekaran/Flutterdev/flutter2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (7 months ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/gopisekaran/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.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.11+0-b60-7590822)

[✓] VS Code (version 1.68.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.42.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.53

• No issues found!
(base) gopisekaran@gopis-MacBook-Air nav % 
```


Please help me to solve the issue ASAP.