Skip to content

[go_router] Assertion error when navigating to hash fragments without leading slash #184109

Description

@AvaPL

Steps to reproduce

  1. Create a minimal Flutter web app with GoRouter 17.1.0 (see the code sample).
  2. Open http://localhost:3000/#foo in a new tab.

Actual results

GoRouter crashes with an assertion error when the browser navigates to a URL with a hash fragment that doesn't start
with /. This occurs with the default hash-based URL strategy on Flutter web.

When the browser extracts the fragment as a path, GoRouter's route matcher fails.

Assertion failed: file:///.../go_router-17.1.0/lib/src/match.dart:256:12
uriPathToCompare.startsWith(newMatchedLocationToCompare)
is not true.

Note: It doesn't happen in go_router 12.1.3 and below.

Expected results

The app should handle the route gracefully or there should be an option to handle it in code. External services may redirect to such URLs - for example, Supabase may redirect to:

http://localhost:3000/?error=access_denied&...#error=access_denied&...

Code sample

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

void main() => runApp(const App());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

final GoRouter _router = GoRouter(
  routes: [
    GoRoute(path: '/', builder: (_, __) => const Home()),
  ],
);

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

  @override
  Widget build(BuildContext context) => const Scaffold();
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.38.5, on macOS 26.3 25D125 darwin-arm64, locale en-US) [67ms]
    • Flutter version 3.38.5 on channel stable at /Users/pawel/fvm/versions/3.38.5
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f6ff1529fd (3 months ago), 2025-12-11 11:50:07 -0500
    • Engine revision 1527ae0ec5
    • Dart version 3.10.4
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging

[✗] Android toolchain - develop for Android devices [31ms]
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✗] Xcode - develop for iOS and macOS [35ms]
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
      Download at: https://developer.apple.com/xcode/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

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

[✓] Connected device (2 available) [50ms]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 26.3 25D125 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 146.0.7680.164

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

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowframeworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyteam-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