Skip to content
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

Fix: Popping a parent route should also pop all child routes #961

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ModularRouterDelegate extends RouterDelegate<ModularBook>
final parallel = page.route;
parallel.popCallback?.call(result);
currentConfiguration?.routes.remove(parallel);
currentConfiguration?.routes.removeWhere((element) => element.parent == parallel.uri.toString());
if (currentConfiguration?.routes.indexWhere(
(element) => element.uri.toString() == parallel.uri.toString()) ==
-1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,45 @@ void main() {
expect(delegate.currentConfiguration?.routes.length, 0);
expect(delegate.navigateHistory, delegate.currentConfiguration?.routes);
});
test('onPopPage with parent/child route', () {
final route = RouteMock();
final parallel = ParallelRouteMock();
when(() => parallel.uri).thenReturn(Uri.parse('/'));
final page = ModularPage(
route: parallel, args: ModularArguments.empty(), flags: ModularFlags());
when(() => route.didPop(null)).thenReturn(true);
when(() => route.settings).thenReturn(page);
when(() => route.isFirst).thenReturn(false);

when(() => reportPopMock.call(parallel)).thenReturn(const Success(unit));

final childRoute = RouteMock();
final childParallel = ParallelRouteMock();
when(() => childParallel.uri).thenReturn(Uri.parse('/child'));
when(() => childParallel.parent).thenReturn('/');
final childPage = ModularPage(
route: childParallel, args: ModularArguments.empty(), flags: ModularFlags());
when(() => childRoute.didPop(null)).thenReturn(true);
when(() => childRoute.settings).thenReturn(childPage);
when(() => childRoute.isFirst).thenReturn(false);

when(() => reportPopMock.call(childParallel)).thenReturn(const Success(unit));

final arguments = ModularArguments.empty();
final getArgsMock = GetArgumentsMock();
final setArgsMock = SetArgumentsMock();
when(() => parser.getArguments).thenReturn(getArgsMock);
when(() => parser.setArguments).thenReturn(setArgsMock);

when(getArgsMock.call).thenReturn(Success(arguments));
when(() => setArgsMock.call(any())).thenReturn(const Success(unit));

delegate.currentConfiguration = ModularBook(routes: [parallel, childParallel]);
expect(delegate.currentConfiguration?.routes.length, 2);
delegate.onPopPage(route, null);
expect(delegate.currentConfiguration?.routes.length, 0);
expect(delegate.navigateHistory, delegate.currentConfiguration?.routes);
});
test('pushNamed with forRoot', () async {
final route1 = ParallelRouteMock();
final route2 = ParallelRouteMock();
Expand Down
2 changes: 1 addition & 1 deletion modular_core/lib/src/tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _Tracker implements Tracker {
continue;
}

moduleTags.remove(tag);
moduleTags.removeWhere((element) => element.startsWith(tag));
if (tag.characters.last == '/') {
moduleTags.remove('$tag/'.replaceAll('//', ''));
}
Expand Down
Loading