Repository: flutter
Issue: [GoRouter] Push() vs Go() different behavior when there is ModalRoute
Labels: package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.24,found in release: 3.26

### Steps to reproduce

Fully reproducible example [https://github.com/petrnymsa/GoRouter-pop-vs-go](https://github.com/petrnymsa/GoRouter-pop-vs-go)

We have Routes: Home (/home) and Profiles (/profiles), with initial route /profiles. 

on Home route I have RouteAware observer. 

- From Profiles, we always navigate to /home with .go()
- From home, I want to navigate to the profile with push(), allowing the user to either switch profiles or go back home.

When the user switches profiles, I would expect either didPush() or didPopNext() to be triggered.

I have reproducible examples where are several scenarios

1. Click on any Profile - confirm dialog appears (this simulates loading dialog before user is logged in) - confirm - you are redirected to home. Notice **didPush** got called.
2. Click on button PUSH profiles
3. Return back - notice **didPopNext()** got called.
4. Click on button PUSH profiles again
5. Click on some profile - confirm dialog - you are on home. Notice that **didPush** nor **didPopNext** not get called.

Different flows with GO to Profiles.

If same process is repeated but with GO profiles, didPush is called always.

**REMOVE dialog**
If showDialog is commented out behavior changes. Now **didPopNext** is always called, even in scenario PUSH profiles.

**ADD Future.delayed**
If you add Future.delayed() after dialog is closed and before context.go is called, again **didPopNext** is called even in scenario PUSH profiles.




### Expected results

When repeat same process in step 5 I would expect at least didPopNext to be called.

### Actual results

None of methods are called

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

final observer = RouteObserver<ModalRoute>();

final router = GoRouter(initialLocation: '/profiles', observers: [
  observer
], routes: [
  GoRoute(path: '/profiles', builder: (context, state) => const ProfilesPage()),
  GoRoute(path: '/home', builder: (context, state) => const HomePage(), routes: [
    GoRoute(path: 'messages', builder: (context, state) => const UnderHomePage()),
  ]),
]);

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class ProfilesPage extends StatelessWidget {
  const ProfilesPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Profiles'),
      ),
      body: ListView(
        children: [
          ...List.generate(
            5,
            (i) => ListTile(
              onTap: () async {
                // COMMENT this showDialog and didPopNext on Home is always triggered.
                await showDialog(
                    context: context,
                    builder: (context) => AlertDialog(
                          content: Text('Profile $i'),
                          actions: [
                            TextButton(
                              onPressed: () => Navigator.of(context).pop(),
                              child: const Text('Close'),
                            ),
                          ],
                        ));
                // IF added delayed with dialog together, didPopNext() is triggered again
                //   await Future.delayed(const Duration(seconds: 1));
                if (context.mounted) {
                  context.go('/home');
                }
              },
              title: Text('Profile $i'),
              trailing: const Icon(Icons.chevron_right),
            ),
          ),
        ],
      ),
    );
  }
}

class _HomePageState extends State<HomePage> with RouteAware {
  @override
  void dispose() {
    observer.unsubscribe(this);
    super.dispose();
  }

  @override
  void didChangeDependencies() {
    observer.subscribe(this, ModalRoute.of(context)!);
    super.didChangeDependencies();
  }

  @override
  void didPush() {
    print('HOME: Did push');
    super.didPush();
  }

  @override
  void didPopNext() {
    print('HOME: didPopNext');
    super.didPopNext();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // In this case I expect only didPopNext() to be called
            ElevatedButton(
              onPressed: () {
                context.push('/profiles');
              },
              child: const Text('PUSH profiles'),
            ),

            // In this case I expect only didPush() to be called
            ElevatedButton(
              onPressed: () {
                context.go('/profiles');
              },
              child: const Text('GO profiles'),
            ),

            // In this case I expec to didPopNext() to be called
            ElevatedButton(
              onPressed: () {
                context.push('/home/messages');
              },
              child: const Text('PUSH messages'),
            ),

            // In this case I expec to didPopNext() to be called
            ElevatedButton(
              onPressed: () {
                context.go('/home/messages');
              },
              child: const Text('GO messages'),
            ),
          ],
        ),
      ),
    );
  }
}

class UnderHomePage extends StatelessWidget {
  const UnderHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: const Text('Messages'),
    );
  }
}

```

</details>


### Screenshots or Video

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.22631.4169], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
[√] Android Studio (version 2021.3)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.93.1)
[√] Connected device (4 available)
[√] Network resources

• No issues found!
```

</details>