Skip to content

Commit

Permalink
Fix rebuilding without query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gilder authored and tomgilder committed Jul 11, 2021
1 parent f6db883 commit 037d25b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.9.5

* Fixed: an issue where pages would not receive query parameters

# 0.9.4

* Fixed: an issue where pages were incorrectly rebuilding, causing state such as the active tab to reset
Expand Down
32 changes: 17 additions & 15 deletions lib/routemaster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,23 @@ class RoutemasterDelegate extends RouterDelegate<RouteData>
);

// Get a page wrapper object for the current route
final page = routerData.builder(routeData);
_assertIsPage(page, routeData.fullPath);

final current = isLastRoute
? _createPageWrapper(
routeRequest: request,
page: page as Page,
routeData: routeData,
)
: _getOrCreatePageWrapper(
routeRequest: request,
routeData: routeData,
currentRoutes: currentRoutes,
routerResult: routerData,
);
late final _PageResult current;
if (isLastRoute) {
final page = routerData.builder(routeData);
_assertIsPage(page, routeData.fullPath);
current = _createPageWrapper(
routeRequest: request,
page: page as Page,
routeData: routeData,
);
} else {
current = _getOrCreatePageWrapper(
routeRequest: request,
routeData: routeData,
currentRoutes: currentRoutes,
routerResult: routerData,
);
}

if (current is _PageWrapperResult) {
final page = current.pageWrapper;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: routemaster
description: Easy-to-use Navigator 2.0 router for web, mobile and desktop. URL-based routing, simple navigation of tabs and nested routes.
version: 0.9.4
version: 0.9.5
homepage: https://github.com/tomgilder/routemaster

environment:
Expand Down
32 changes: 32 additions & 0 deletions test/router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,38 @@ void main() {
expect(find.byType(DefaultNotFoundPage), findsOneWidget);
});

testWidgets(
"Doesn't rebuild page hierarchy when nested page route pushed on top",
(tester) async {
final queryParamBuilds = <String?>[];

final delegate = RoutemasterDelegate(
routesBuilder: (BuildContext context) => RouteMap(
routes: {
'/': (routeData) => const Redirect(
'/one',
queryParameters: {'query1': 'val1'},
),
'/one': (routeData) {
queryParamBuilds.add(routeData.queryParameters['query1']);
return const MaterialPageOne();
},
'/one/two': (_) => const MaterialPageTwo(),
},
),
);

await tester.pumpWidget(MaterialApp.router(
routeInformationParser: const RoutemasterParser(),
routerDelegate: delegate,
));

delegate.push('/one/two');
await tester.pump();

expect(queryParamBuilds, ['val1']);
});

testWidgets('Unknown startup URL redirects to another page', (tester) async {
await tester.pumpWidget(
MaterialApp.router(
Expand Down

0 comments on commit 037d25b

Please sign in to comment.