Closed oravecz closed 2 years ago
fixed in v2.0.0. @oravecz please verify.
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');
});
glad to here it works for you. it was a great feature suggestion.
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.