Skip to content

[go_router] URL changes to / while async redirect completes #112997

Closed

Description

@MarcBritton

When a parent route is acting as a guard route and has an asynchronous redirect function assigned to it, the URL path in the browser changes to / while the redirect function completes.

I would like/expect to see the URL path remain unchanged until the redirect function completes.

Consider the following simple GoRouter:

final GoRouter testRouter = GoRouter(
    routes: [
      GoRoute(
        path: '/',
        redirect: (context, state) => '/parent/child',
      ),
      GoRoute(
        path: '/parent',
        builder: (context, state) => const Text('parent'),
        redirect: (context, state) async {
          await Future.delayed(const Duration(seconds: 5));
          return null;
        },
        routes: <RouteBase>[
          GoRoute(
            path: 'child',
            builder: (context, state) => const Text('child'),
          )
        ],
      ),
    ],
  );

If you run a Flutter Web app with this GoRouter enabled in Chrome, and then manually navigate to localhost:<port>/parent/child, the URL in the browser changes from what you entered to simply / while the parent route redirect function runs, and then changes back to the destination route /parent/child on completion.

I think the path in the browser should remain as /parent/child while the redirect runs. Why doesn't it?

Activity

  1. MarcBritton commented on Oct 6, 2022

    @MarcBritton
    Author

    This is what it looks like running in a browser:

    Screen.Recording.2022-10-06.at.1.16.26.pm.mov
  2. added
    in triage
    on Oct 6, 2022
  3. huycozy commented on Oct 6, 2022

    @huycozy
    Member

    @MarcBritton I can reproduce the issue on the latest stable and master channels with go_router: ^5.0.5.
    Keeping this open for further insights from the team.

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-x64, locale en-VN)
        • Flutter version 3.3.4 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision eb6d86ee27 (23 hours ago), 2022-10-04 22:31:45 -0700
        • Engine revision c08d7d5efc
        • Dart version 2.18.2
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 31.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode14.0.1.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • 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 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2022.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 70.0.5
        • Dart plugin version 222.4167.21
    
    [✓] IntelliJ IDEA Community Edition (version 2022.1.1)
        • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/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.71.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.48.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 12.6 21G115 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 105.0.5195.125
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 3.5.0-2.0.pre.14, on macOS 12.6 21G115 darwin-x64, locale en-VN)
        • Flutter version 3.5.0-2.0.pre.14 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 59d68e03ee (15 minutes ago), 2022-10-05 23:53:34 -0400
        • Engine revision 5f2daf05e0
        • Dart version 2.19.0 (build 2.19.0-273.0.dev)
        • DevTools version 2.18.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 31.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
        • Xcode at /Applications/Xcode14.0.1.app/Contents/Developer
        • Build 14A400
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • 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 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2022.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 70.0.5
        • Dart plugin version 222.4167.21
    
    [✓] IntelliJ IDEA Community Edition (version 2022.1.1)
        • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/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.71.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.48.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 12.6 21G115 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 105.0.5195.125
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  4. added
    package
    has reproducible steps
    p: go_router
    found in release: 3.3
    found in release: 3.5
    and removed
    in triage
    on Oct 6, 2022
  5. added
    P2
    on Oct 10, 2022
  6. changed the title [-][go_router] async redirects on guard routes result in browser URL change[/-] [+][go_router] URL changes to / while async redirect completes[/+] on Oct 26, 2022
  7. PranayDosii commented on Nov 24, 2022

    @PranayDosii

    Any updates on this issue

  8. PranayDosii commented on Jan 8, 2023

    @PranayDosii

    I tried the new version of go_router: ^6.0.1 and it is working as expected. In the changelog, they fixed the async redirect issue in version 5.2.4 link

  9. MarcBritton commented on Jan 10, 2023

    @MarcBritton
    Author

    I retested and confirmed the bug is fixed in 6.0.1.

  10. grukillerkams commented on Jan 29, 2023

    @grukillerkams

    it's not fixed, i am using 6.0.1 and facing the same issue

  11. github-actions commented on Mar 3, 2023

    @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.

  12. locked as resolved and limited conversation to collaborators on Mar 3, 2023
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

    P2found in release: 3.3found in release: 3.5has reproducible stepsp: go_routerpackage

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions