Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go_router] ShellRoute should have a redirect method similar to GoRoute #114559

Open
ahmednfwela opened this issue Nov 3, 2022 · 4 comments
Open
Labels
c: proposal A detailed proposal for a change to Flutter p: go_router The go_router package P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team

Comments

@ahmednfwela
Copy link

ahmednfwela commented Nov 3, 2022

It is a common use case that a developer would want to guard an entire area in the app wrapped with ShellRoute
e.g. dashboard area

ShellRoute(
  redirect: (context, state) {
    //guard for authenticated users
  },
  builder: (context, state, child) => DashboardShellView(child: child),
  routes: [
    //sub routes
    GoRoute(path: '/orders'),
    GoRoute(path: '/dashboard'),
    GoRoute(path: '/short_route'),
  ],
),

there are 2 workarounds for this:

  1. repeat the redirect logic for each sub route of a shell route
  2. Group all guarded routes to be put under a single GoRoute
    e.g.:
ShellRoute(
  builder: (context, state, child) => DashboardShellView(child: child),
  routes: [
    //sub routes
    GoRoute(
      path:'/dashboard',
      redirect: (context, state) {
        //guard for authenticated users
      },
      routes: [
        GoRoute(path: 'orders'),
        GoRoute(path: 'short_route'),
      ],
    ),
  ],
),

however this has the downside of /short_route getting changed to /dashboard/short_route, and /orders getting changed to /dashboard/orders which might not be desirable

@huycozy huycozy added the in triage Presently being triaged by the triage team label Nov 3, 2022
@huycozy
Copy link
Member

huycozy commented Nov 3, 2022

Hi @ahmednfwela, I label this issue as a proposal for further insights from the team. Current package version: go_router: ^5.1.2.

@huycozy huycozy added p: first party package flutter/packages repository. See also p: labels. c: proposal A detailed proposal for a change to Flutter p: go_router The go_router package and removed in triage Presently being triaged by the triage team labels Nov 3, 2022
@stuartmorgan stuartmorgan added the P3 Issues that are less important to the Flutter project label Nov 15, 2022
@aveit
Copy link

aveit commented May 8, 2023

Hello guys!

Do we have an update on this one?

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team labels Jul 8, 2023
@Thrajnor
Copy link

Hi! Since this issue is regarded as unimportant, do you guys have any good solution to aforementioned problem? For now i'm doing guards for every route separately, but now i have case where i want to run something whenever user enters one of the Shelled routes, adding it to every guarded route seems redundant

@danielmahon
Copy link

danielmahon commented Aug 24, 2023

@Thrajnor I have previously just subclassed GoRouteData and implemented an auth redirect there, and then any route-specific redirects in the regular route. Just make sure to call super.redirect(context, state) where you need. I was hoping to do the same with the new Typed Shell Routes so I could eventually drop that.

class HomeRoute extends PrivateRouteData {...
class LoginRoute extends PublicRouteData {...

chunhtai added a commit to flutter/packages that referenced this issue May 9, 2024
Possible solution for: flutter/flutter#114559

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [X] I signed the [CLA].
- [X] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [X] I [linked to at least one issue that this PR fixes] in the
description above.
- [X] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [X] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

---------

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Victor Ohashi <victor.ohashi@govoll.com>
auto-submit bot pushed a commit that referenced this issue May 13, 2024
flutter/packages@6c4482a...1412041

2024-05-13 stuartmorgan@google.com [in_app_purchase] Update country code Android example (flutter/packages#6722)
2024-05-13 engine-flutter-autoroll@skia.org Roll Flutter from 1dfb46e to 1255435 (6 revisions) (flutter/packages#6723)
2024-05-13 43054281+camsim99@users.noreply.github.com [camera] Change default Android implementation from `camera_android` to `camera_android_camerax` (flutter/packages#6629)
2024-05-13 15619084+vashworth@users.noreply.github.com [image_picker_ios] Make all headers public for SwiftPM to keep inline with CocoaPods (flutter/packages#6707)
2024-05-12 engine-flutter-autoroll@skia.org Roll Flutter from 2aa05c1 to 1dfb46e (3 revisions) (flutter/packages#6715)
2024-05-11 engine-flutter-autoroll@skia.org Roll Flutter from 2bfb1b0 to 2aa05c1 (26 revisions) (flutter/packages#6713)
2024-05-10 stuartmorgan@google.com [quick_actions] Add Swift Package Manager support (flutter/packages#6682)
2024-05-10 stuartmorgan@google.com [url_launcher] Add Swift Package Manager support (flutter/packages#6677)
2024-05-10 43054281+camsim99@users.noreply.github.com [Android][webview_flutter] Run integration tests on emulators running Android 34 (flutter/packages#6499)
2024-05-10 50643541+Mairramer@users.noreply.github.com [image_picker_android] - will fix crash on Android 12+ devices (flutter/packages#6691)
2024-05-10 43054281+camsim99@users.noreply.github.com [camerax] Make fixes required to swap camera_android_camerax for camera_android (flutter/packages#6697)
2024-05-10 737941+loic-sharma@users.noreply.github.com Update .gitignore for Swift Package Manager (flutter/packages#6705)
2024-05-10 34871572+gmackall@users.noreply.github.com [quick_actions_android] Switch to `Compat` version of `ShortcutManager` to support Google surfaces (flutter/packages#6638)
2024-05-10 737941+loic-sharma@users.noreply.github.com [local_auth_darwin] Adds Swift Package Manager compatibility (flutter/packages#6708)
2024-05-10 engine-flutter-autoroll@skia.org Roll Flutter from 00f4066 to 2bfb1b0 (9 revisions) (flutter/packages#6706)
2024-05-09 38299943+VictorOhashi@users.noreply.github.com [go_router] Feat add route redirect shellroutes (#114559) (flutter/packages#6432)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this issue May 22, 2024
Possible solution for: flutter/flutter#114559

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [X] I signed the [CLA].
- [X] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [X] I [linked to at least one issue that this PR fixes] in the
description above.
- [X] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [X] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

---------

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Victor Ohashi <victor.ohashi@govoll.com>
arc-yong pushed a commit to Arctuition/packages-arc that referenced this issue Jun 14, 2024
Possible solution for: flutter/flutter#114559

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [X] I signed the [CLA].
- [X] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [X] I [linked to at least one issue that this PR fixes] in the
description above.
- [X] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [X] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

---------

Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Victor Ohashi <victor.ohashi@govoll.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: proposal A detailed proposal for a change to Flutter p: go_router The go_router package P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team triaged-go_router Triaged by Go Router team
Projects
No open projects
Status: No status
Development

No branches or pull requests

7 participants