Skip to content

Commit

Permalink
Fix forward history bug (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gilder authored Oct 6, 2021
1 parent f011110 commit 74f928f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.0-dev4

* Fixes a bug with forward history navigation.

# 0.10.0-dev3

**Important:** this release has some major breaking changes with how Routemaster
Expand Down
2 changes: 1 addition & 1 deletion lib/src/route_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class RouteHistory {
final routeHasChanged = _history.isEmpty || route != _history[_index];

if (routeHasChanged) {
_clearForwardEntries();
_history.add(route);
_index++;
_clearForwardEntries();
}
}

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.10.0-dev3
version: 0.10.0-dev4
homepage: https://github.com/tomgilder/routemaster

environment:
Expand Down
39 changes: 39 additions & 0 deletions test/history_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,43 @@ void main() {
expect(routemaster.history.canGoForward, isFalse);
expect(routemaster.history.forward(), isFalse);
});

testWidgets('Changing second route works correctly', (tester) async {
final delegate = RoutemasterDelegate(routesBuilder: (_) => routeMap);

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

final routemaster = Routemaster.of(pageOneKey.currentContext!);
final history = routemaster.history;

// Go to /two
routemaster.push('/two');
await tester.pumpPageTransition();
expect(find.byType(PageTwo), findsOneWidget);

// Go back to /
history.back();
await tester.pumpPageTransition();
expect(find.byType(PageOne), findsOneWidget);

// Go to /three
routemaster.push('/three');
await tester.pumpPageTransition();
expect(find.byType(PageThree), findsOneWidget);

// Go back to /
history.back();
await tester.pumpPageTransition();
expect(find.byType(PageOne), findsOneWidget);

// Go forward to /three
history.forward();
await tester.pumpPageTransition();
expect(find.byType(PageThree), findsOneWidget);
});
}

0 comments on commit 74f928f

Please sign in to comment.