Skip to content

[go_router] GoRouter remove query parameter when app loaded/refreshed #137513

@dannndi

Description

@dannndi

Is there an existing issue for this?

What package does this bug report belong to?

go_router

What target platforms are you seeing this bug on?

Web

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
  go_router:
    dependency: "direct main"
    description:
      name: go_router
      sha256: e156bc1b2088eb5ece9351bccd48c3e1719a4858eacbd44e59162e98a68205d1
      url: "https://pub.dev"
    source: hosted
    version: "12.0.1"

Steps to reproduce

  1. Create app using go_router
  2. Build to web
  3. on chrome input url in tab browser `localhost:port/home?q=test'

Expected results

when page loaded query parameter not get removed
`/home?q=test'

Actual results

notice that when app loaded, query parameter get removed
localhost:port/home

Code sample

Code sample
void main() async {
  MainModule.init();
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: AppRoute.router,
      title: "Flutter Playground",
  }
}

class AppRoute {
  AppRoute._();
  
  static final GoRouter router = GoRouter(
    debugLogDiagnostics: true,
    initialLocation: "/home",
    routes: [
      GoRoute(
        path: "/home",
        builder: (context, state) {
          final query = state.uri.queryParameters["q"] ?? "";
          return Scaffold(
            appBar: AppBar(
              title: const Text("Home Screen"),
            ),
            body: Center(
              child: Text(
                  "Query Data : ${query.isEmpty ? "Empty" : query}",
               ),
            ),
          );
        },
      ),
    ],
  );
}

Screenshots or Videos

Screenshots / Video demonstration
Screen.Recording.2023-10-30.at.09.09.23.mov

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.0.1 22A400 darwin-arm64, locale en-ID)
    • Flutter version 3.10.6 on channel stable at /Users/dandisupriyadi/Documents/Repsitory/Flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (4 months ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/dandisupriyadi/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • Java binary at: /Applications/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 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.1

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

[✓] Android Studio (version 2022.3)
    • 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 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2022.3.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.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.80.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (3 available)
    • iPhone 14 (mobile) • E729289D-2328-479D-8001-E7E098242ECE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64
    • 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

    P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowfound 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.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions