Skip to content

[GoRouter] onExit does not work with ShellRoute #137829

Description

@quoc-huynh-cosee

Is there an existing issue for this?

Steps to reproduce

  1. Start project
  2. Click the Go to MyPage button
  3. Click the BackButton

Expected results

It should not be possible to go back to HomePage since onExit always returns false.

Actual results

We can go back to HomePage.

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: GoRouter(
        routes: [
          GoRoute(
            path: '/',
            name: 'home',
            builder: (_, __) => const HomePage(),
            routes: [
              ShellRoute(
                builder: (_, __, child) => child,
                routes: [
                  GoRoute(
                    path: 'page',
                    name: 'page',
                    onExit: (context) => false,
                    builder: (_, __) => const MyPage(),
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('HomePage'),
      ),
      body: Center(
        child: TextButton(
          onPressed: () => context.goNamed('page'),
          child: Text('Go to MyPage'),
        ),
      ),
    );
  }
}

class MyPage extends StatelessWidget {
  const MyPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MyPage'),
        leading: BackButton(
          onPressed: () => context.pop(),
        ),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-x64, locale de-DE)
    • Flutter version 3.13.9 on channel stable at /Users/huynh/.asdf/installs/flutter/3.13.9-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (vor 9 Tagen), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/huynh/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/huynh/Library/Android/sdk
    • Java binary at: /Users/huynh/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10811636/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/huynh/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10811636/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.6b829.9-10027231)

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/huynh/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10671973/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.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.4)
    • IntelliJ at /Users/huynh/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 76.1.4
    • Dart plugin version 232.10072.19

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.4)
    • IntelliJ at /Users/huynh/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/232.10203.10/IntelliJ IDEA.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

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
    • IntelliJ at /Users/huynh/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/232.10072.27/IntelliJ IDEA.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

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (5 available)
    • 2203129G (mobile)                  • adb-723c1722-1XNpMz._adb-tls-connect._tcp. • android-arm64  • Android 13 (API 33)
    • Android SDK built for x86 (mobile) • emulator-5554                              • android-x86    • Android 11 (API 30) (emulator)
    • iPhone 15 (mobile)                 • DB01FF6A-DA97-4FF9-9268-4B0FE07D2FFE       • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)                    • macos                                      • darwin-x64     • macOS 14.0 23A344 darwin-x64
    • Chrome (web)                       • chrome                                     • web-javascript • Google Chrome 118.0.5993.117

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions