Skip to content

Back button closes app instead of navigating to first tab in go_router 17.1.0 with ShellRoute #181945

Description

@souravkk2024

Steps to reproduce

After upgrading to Flutter 3.38.6 and go_router 17.1.0, the back button closes the app when pressed on tabs 2, 3, etc., instead of navigating to the first tab. This only works correctly on the first tab.

  1. Upgrade Flutter to 3.38.6
  2. Upgrade go_router to 17.1.0
  3. Set up a ShellRoute with multiple tab routes (e.g., dashboard, home, profile)
  4. Navigate to any tab other than the first (e.g., 3rd tab)
  5. Press the system back button
  6. Expected: Navigate to the first tab
  7. Actual: App closes immediately

Expected results

Expected Behavior

  1. Pressing back on tab 2, 3, etc. should navigate to tab 1
  2. Pressing back on tab 1 should show an exit confirmation dialog
  3. Only after confirming should the app exit

Actual results

    1. Pressing back on any tab other than the first closes the app immediately
    1. No navigation to the first tab occurs
    1. No exit dialog is shown

Code sample

Code sample
ShellRoute(
  routes: [
    GoRoute(path: '/main_screen/dashboard', ...),
    GoRoute(path: '/main_screen/home', ...),
    GoRoute(path: '/main_screen/profile', ...),
    // ... more tabs
  ],
  builder: (context, state, child) {
    return MainScreen(child: child);
  },
)

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.38.9, on Microsoft Windows [Version 10.0.22000.2538], locale en-IN)
    ! Flutter version 3.38.9 on channel [user-branch] at C:\Users\DeLL\Documents\flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
[√] Windows Version (11 Pro 64-bit, 21H2, 2009)
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.13 Preview 1.0)
[√] Connected device (5 available)
[√] Network resources

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: routesNavigator, Router, and related APIs.p: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions