Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Named route from redirect guard #69

Closed
oravecz opened this issue Oct 8, 2021 · 3 comments
Closed

Named route from redirect guard #69

oravecz opened this issue Oct 8, 2021 · 3 comments
Labels

Comments

@oravecz
Copy link

oravecz commented Oct 8, 2021

The decision was made to return a route's path from the redirect guard function. It would have been convenient to expose context to the redirect function so the user can choose to go/push a path/named route.

@csells csells added the enhancement New feature or request label Oct 8, 2021
@csells
Copy link
Owner

csells commented Oct 8, 2021

fixed in v2.0.0. @oravecz please verify.

@oravecz
Copy link
Author

oravecz commented Oct 8, 2021

Works well. It took me a while to notice the API to use (state.namedRoute("route_name")), but I got there in the end.

Here is a test that is closest to my use case (with the redirect function not on the top-level router.

  test('sub-level redirect w/ named routes', () {
    final routes = [
      GoRoute(
        name: 'home',
        path: '/',
        pageBuilder: (builder, state) => HomePage(),
        routes: [
          GoRoute(
              name: 'dummy',
              path: 'dummy',
              pageBuilder: (builder, state) => DummyPage(),
              redirect: (state) => state.namedLocation('login'),
          ),
          GoRoute(
            name: 'login',
            path: 'login',
            pageBuilder: (builder, state) => LoginPage(),
          ),
        ],
      ),
    ];

    final router = GoRouter(
      initialLocation: '/dummy',
      debugLogDiagnostics: true,
      routes: routes,
      errorPageBuilder: _dummy,
    );
    expect(router.location, '/login');
  });

@csells
Copy link
Owner

csells commented Oct 8, 2021

glad to here it works for you. it was a great feature suggestion.

@csells csells closed this as completed Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants