Skip to content

fix: [go_router] Extra parameter is always null in route level redirect callback #2404

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

Merged
merged 10 commits into from
Aug 2, 2022
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.5

- Fixes a bug where calling extra parameter is always null in route level redirect callback

## 4.2.4

- Rewrites Readme and examples.
Expand Down
1 change: 1 addition & 0 deletions packages/go_router/lib/src/redirection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ RouteMatchList redirect(RouteMatchList prevMatchList,
name: top.route.name,
path: top.route.path,
fullpath: top.fullpath,
extra: top.extra,
params: top.decodedParams,
queryParams: top.queryParams,
),
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 4.2.4
version: 4.2.5
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
48 changes: 48 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,54 @@ void main() {
(router.screenFor(matches.first) as TestErrorScreen).ex, isNotNull);
log.info((router.screenFor(matches.first) as TestErrorScreen).ex);
});

testWidgets('extra not null in redirect', (WidgetTester tester) async {
bool isCallTopRedirect = false;
bool isCallRouteRedirect = false;

final List<GoRoute> routes = <GoRoute>[
GoRoute(
name: 'home',
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
routes: <GoRoute>[
GoRoute(
name: 'login',
path: 'login',
builder: (BuildContext context, GoRouterState state) {
return const LoginScreen();
},
redirect: (GoRouterState state) {
isCallRouteRedirect = true;
expect(state.extra, isNotNull);
return null;
},
routes: <GoRoute>[],
),
],
),
];

final GoRouter router = await createRouter(
routes,
tester,
redirect: (GoRouterState state) {
if (state.location == '/login') {
isCallTopRedirect = true;
expect(state.extra, isNotNull);
}

return null;
},
);

router.go('/login', extra: 1);
await tester.pump();

expect(isCallTopRedirect, true);
expect(isCallRouteRedirect, true);
});
});

group('initial location', () {
Expand Down