Skip to content

[go_router][Web] Special characters are not encoded in URLs on browser #171757

Closed

Description

@glaceon2000

Steps to reproduce

Put special characters, encoded or not, in url, then hit Refresh. They are automatically converted back to its non-encoded form.

Expected results

Special characters are not encoded in urls

Actual results

Special characters are encoded in urls

Code sample

main.dart
import 'package:flutter/material.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:go_router/go_router.dart';
import 'package:testing_textfield/router.dart';

void main() {
  GoRouter.optionURLReflectsImperativeAPIs = true;
  setUrlStrategy(PathUrlStrategy());
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final _router = GoRouter(
    initialLocation: '/',
    routes: $appRoutes,
    debugLogDiagnostics: true,
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'TESTING GO ROUTER',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        scaffoldBackgroundColor: const Color.fromARGB(255, 235, 235, 241),
      ),
      routeInformationParser: _router.routeInformationParser,
      routeInformationProvider: _router.routeInformationProvider,
      routerDelegate: _router.routerDelegate,
    );
  }
}
router.dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:testing_textfield/test_text_field.dart';

part 'router.g.dart';

@TypedGoRoute<HomeRouter>(path: '/')
class HomeRouter extends GoRouteData {
  const HomeRouter({this.text});
  final String? text;
  @override
  Page<void> buildPage(BuildContext context, GoRouterState state) {
    return NoTransitionPage(
        child: Scaffold(
      backgroundColor: Colors.white,
      key: UniqueKey(),
      body: TestTextFieldScreen(text: text),
    ));
  }
}
router.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'router.dart';

// **************************************************************************
// GoRouterGenerator
// **************************************************************************

List<RouteBase> get $appRoutes => [
      $homeRouter,
    ];

RouteBase get $homeRouter => GoRouteData.$route(
      path: '/',
      factory: $HomeRouterExtension._fromState,
    );

extension $HomeRouterExtension on HomeRouter {
  static HomeRouter _fromState(GoRouterState state) => HomeRouter(
        text: state.uri.queryParameters['text'],
      );

  String get location => GoRouteData.$location(
        '/',
        queryParams: {
          if (text != null) 'text': text,
        },
      );

  void go(BuildContext context) => context.go(location);

  Future<T?> push<T>(BuildContext context) => context.push<T>(location);

  void pushReplacement(BuildContext context) =>
      context.pushReplacement(location);

  void replace(BuildContext context) => context.replace(location);
}
test_text_field.dart
import 'package:flutter/material.dart';
import 'package:testing_textfield/router.dart';

class TestTextFieldScreen extends StatefulWidget {
  const TestTextFieldScreen({super.key, this.text});
  final String? text;

  @override
  State<TestTextFieldScreen> createState() => _TestTextFieldScreenState();
}

class _TestTextFieldScreenState extends State<TestTextFieldScreen> {
  final ctrl = TextEditingController();
  @override
  void dispose() {
    ctrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          TextFormField(
            controller: ctrl,
          ),
          const SizedBox(height: 20),
          Text('Non decoded text: ' + (widget.text ?? '')),
          const SizedBox(height: 20),
          Text('Decoded text: ' + Uri.decodeQueryComponent(widget.text ?? '')),
          const SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              OutlinedButton(
                  onPressed: () {
                    HomeRouter(text: ctrl.text).go(context);
                  },
                  child: const Text('Send non encoded text')),
              const SizedBox(width: 20),
              OutlinedButton(
                  onPressed: () {
                    HomeRouter(text: Uri.encodeQueryComponent(ctrl.text))
                        .go(context);
                  },
                  child: const Text('Send encoded text')),
            ],
          )
        ],
      ),
    );
  }
}

Screenshots or Video

Screen.Recording.2025-07-08.at.15.58.19.mov
Screenshots / Video demonstration

[Upload media here]

Logs

Logs
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
This app is linked to the debug service: ws://127.0.0.1:53889/-RI1VrrJ2k8=/ws
Debug service listening on ws://127.0.0.1:53889/-RI1VrrJ2k8=/ws
Debug service listening on ws://127.0.0.1:53889/-RI1VrrJ2k8=/ws
[GoRouter] Full paths for routes:
└─/ (Widget)

[GoRouter] setting initial location /
[GoRouter] going to /?text=a%2Bb
[GoRouter] Full paths for routes:
└─/ (Widget)

[GoRouter] setting initial location /
[GoRouter] going to /?text=a%252Bb
[GoRouter] Full paths for routes:
└─/ (Widget)

[GoRouter] setting initial location /

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.24.3, on macOS 15.2 24C101 darwin-arm64, locale en-VN)
    ! Flutter version 3.24.3 on channel [user-branch] at /Users/mht/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.
    • Framework revision 2663184aa7 (10 months ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/mht/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
    ! CocoaPods 1.11.3 out of date (1.13.0 is recommended).
        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
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

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

[✓] Android Studio (version 2024.1)
    • 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.11+0-17.0.11b1207.24-11852314)

[✓] Android Studio (version 2021.2)
    • Android Studio at /Volumes/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 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] VS Code (version 1.98.2)
    • VS Code at /Volumes/Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.2 24C101 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.2 24C101 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 138.0.7204.93

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

! Doctor found issues in 2 categories.

Activity

  1. darshankawar commented on Jul 8, 2025

    @darshankawar
    Member

    @glaceon2000
    Please check #140139 and #101757 (comment) to see if they help further in your case or not.
    I also suggest you to upgrade to latest stable and re-run to check if you still get same behavior or not.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 8, 2025
  3. glaceon2000 commented on Jul 9, 2025

    @glaceon2000
    Author

    @glaceon2000 Please check #140139 and #101757 (comment) to see if they help further in your case or not. I also suggest you to upgrade to latest stable and re-run to check if you still get same behavior or not.

    I have tested on flutter version 3.29.0 and go_router 16.0.0, which produced the same problem. My issue is not similar to the issues you've linked. In fact it's quite the opposite, as in I put encoded values and they're converted on the url to their non-encoded form.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 9, 2025
  5. darshankawar commented on Jul 10, 2025

    @darshankawar
    Member

    I have tested on flutter version 3.29.0 and go_router 16.0.0,

    Please try with latest stable (3.32.5)

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 10, 2025
  7. glaceon2000 commented on Jul 11, 2025

    @glaceon2000
    Author

    I have tested on flutter version 3.29.0 and go_router 16.0.0,

    Please try with latest stable (3.32.5)

    I've tried with 3.32.5. The same behavior persists

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 11, 2025
  9. darshankawar commented on Jul 11, 2025

    @darshankawar
    Member

    Thanks for the update. Seeing the same behavior as reported.

    stable : 3.32.5
    master : 3.33.0-1.0.pre.905
    
  10. added
    packageflutter/packages repository. See also p: labels.
    platform-webWeb applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Jul 11, 2025
  11. 2 remaining items

  12. added
    P3Issues that are less important to the Flutter project
    on Jul 15, 2025
  13. ArthurHlt commented on Sep 26, 2025

    @ArthurHlt

    @glaceon2000 I've found an issue and send a PR, but if you need a workaround this is what we have done in our code:

    import 'package:flutter/foundation.dart';
    import 'package:flutter/services.dart';
    import 'package:flutter/cupertino.dart';
    import 'package:go_router/go_router.dart';
    
    class GoRouteInfoProviderCustom extends RouteInformationProvider {
      final GoRouteInformationProvider _provider;
    
      GoRouteInfoProviderCustom(this._provider);
    
      // this is here to fix the issue with go_router and web
      // see pr: https://github.com/flutter/flutter/pull/176029
      @override
      void routerReportsNewRouteInformation(
        RouteInformation routeInformation, {
        RouteInformationReportingType type = RouteInformationReportingType.none,
      }) {
        _provider.routerReportsNewRouteInformation(routeInformation, type: type);
        if (kIsWeb) {
          SystemChannels.navigation
              .invokeMethod<void>('routeInformationUpdated', <String, dynamic>{
            'location': routeInformation.uri.toString(),
            'state': routeInformation.state,
            'replace': false,
          });
        }
      }
    
      @override
      void addListener(VoidCallback listener) {
        _provider.addListener(listener);
      }
    
      @override
      void removeListener(VoidCallback listener) {
        _provider.removeListener(listener);
      }
    
      @override
      RouteInformation get value => _provider.value;
    }
    
    class GoRouterCustom implements RouterConfig<RouteMatchList> {
      final GoRouter _router;
      late final GoRouteInfoProviderCustom _routeInfoProvider;
    
      GoRouterCustom(this._router) {
        _routeInfoProvider =
            GoRouteInfoProviderCustom(_router.routeInformationProvider);
      }
    
      @override
      BackButtonDispatcher? get backButtonDispatcher =>
          _router.backButtonDispatcher;
    
      @override
      RouteInformationParser<RouteMatchList>? get routeInformationParser =>
          _router.routeInformationParser;
    
      @override
      RouteInformationProvider? get routeInformationProvider => _routeInfoProvider;
    
      @override
      RouterDelegate<RouteMatchList> get routerDelegate => _router.routerDelegate;
    }

    For usage after:

    import 'package:go_router/go_router.dart';
    
    RouterConfig<RouteMatchList> makeApplicationRouter() {
        GoRouter goRouter = GoRouter(
        // ..
        );
        if (kIsWeb) {
          return GoRouterCustom(goRouter);
        }
        return goRouter;
    }
  14. glaceon2000 commented on Oct 2, 2025

    @glaceon2000
    Author

    @ArthurHlt Thanks a lot.

  15. glaceon2000 commented on May 4, 2026

    @glaceon2000
    Author

    No update?

  16. github-actions commented on Oct 17, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  17. locked as resolved and limited conversation to collaborators on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has 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-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions