From 9a8e6dda173c4d8639e9a3cfc43b344afcc318d7 Mon Sep 17 00:00:00 2001 From: felipe-labbits Date: Mon, 28 Jun 2021 20:52:21 -0300 Subject: [PATCH 1/3] Fix tests orthography --- .../modular_route_information_parse_test.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/flutter_modular/test/src/presenters/navigation/modular_route_information_parse_test.dart b/flutter_modular/test/src/presenters/navigation/modular_route_information_parse_test.dart index 2bd7e76d..183ec8f6 100644 --- a/flutter_modular/test/src/presenters/navigation/modular_route_information_parse_test.dart +++ b/flutter_modular/test/src/presenters/navigation/modular_route_information_parse_test.dart @@ -88,19 +88,19 @@ main() { expect(route.args.fragment, 'abcd'); }); - test('should retrive Widcard route when not exist path', () async { + test('should retrieve Wildcard route when not exist path', () async { final route = await parse.selectRoute('/paulo', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); }); - test('should retrive Widcard route when path with query params doesnt exist', () async { + test('should retrieve Wildcard route when path with query params doesn\'t exist', () async { final route = await parse.selectRoute('/paulo?adbc=1234', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); }); - test('should retrive Widcard route when path with fragment doesnt exist', () async { + test('should retrieve Wildcard route when path with fragment doesn\'t exist', () async { final route = await parse.selectRoute('/paulo#adbc=1234', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); @@ -112,21 +112,21 @@ main() { }); group('Multi Module | ', () { - test('should retrive route /mock', () async { + test('should retrieve route /mock', () async { final route = await parse.selectRoute('/mock', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); expect(route.path, '/mock/'); }); - test('should retrive route /mock/', () async { + test('should retrieve route /mock/', () async { final route = await parse.selectRoute('/mock/', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); expect(route.path, '/mock/'); }); - test('should retrive route /mock/list', () async { + test('should retrieve route /mock/list', () async { final route = await parse.selectRoute('/mock/list', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); @@ -201,14 +201,14 @@ main() { expect(route.args.fragment, 'abcd'); }); - test('should retrive dynamic route /mock/list/:id', () async { + test('should retrieve dynamic route /mock/list/:id', () async { final route = await parse.selectRoute('/mock/list/3', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, route.args).toString(), '3'); expect(route.path, '/mock/list/3'); }); - test('should retrive Widcard route when not exist path', () async { + test('should retrieve Wildcard route when not exist path', () async { final route = await parse.selectRoute('/mock/paulo', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); @@ -232,7 +232,7 @@ main() { }); group('Outlet Module | ', () { - test('should retrive route /home/tab1', () async { + test('should retrieve route /home/tab1', () async { final route = await parse.selectRoute('/home/tab1', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); @@ -241,7 +241,7 @@ main() { expect(route.routerOutlet[0].child!(context, ModularArguments()), isA()); expect(route.routerOutlet[0].path, '/home/tab1'); }); - test('should retrive route /home/tab2/:id', () async { + test('should retrieve route /home/tab2/:id', () async { final route = await parse.selectRoute('/home/tab2/3', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); @@ -254,7 +254,7 @@ main() { expect(parse.selectRoute('/home/tab3', module: ModuleMock()), throwsA(isA())); }); - test('should retrive route (Module)', () async { + test('should retrieve route (Module)', () async { final route = await parse.selectRoute('/mock/home', module: ModuleMock()); expect(route, isNotNull); expect(route.child!(context, ModularArguments()), isA()); From c2da1075241e85a9ea7978b84194c049e51b58e1 Mon Sep 17 00:00:00 2001 From: felipe-labbits Date: Mon, 28 Jun 2021 20:57:38 -0300 Subject: [PATCH 2/3] Fix wildcard search method --- .../modular_route_information_parser.dart | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart b/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart index 1414423b..233b089e 100644 --- a/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart +++ b/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart @@ -100,7 +100,7 @@ class ModularRouteInformationParser extends RouteInformationParser if (router != null) { router = router.copyWith( modulePath: router.modulePath == null ? '/' : tempRouteName, - currentModule: route.currentModule, + currentModule: router.currentModule ?? route.currentModule, guardedRoute: router.guardedRoute ?? route.guardedRoute, guards: [if (route.guards != null) ...route.guards!, if (router.guards != null) ...router.guards!], ); @@ -207,27 +207,32 @@ class ModularRouteInformationParser extends RouteInformationParser String path, Module module, ) { - ModularRoute? finded; + ModularRoute? found; - final segments = path.split('/')..removeLast(); - final length = segments.length; - for (var i = 0; i < length; i++) { - final localPath = segments.join('/'); + var pathSegments = path.split('/')..removeLast(); + final length = pathSegments.length; + for(var i = 0; i < length; i++) { + final localPath = pathSegments.join('/'); final route = _searchInModule(module, "", Uri.parse(localPath.isEmpty ? '/' : localPath)); - if (route != null) { - if (route.children.isNotEmpty && route.routerName != '/') { - finded = route.children.last.routerName == '**' ? route.children.last : null; + + if(route != null) { + if(route.children.isEmpty) { + found = route.currentModule?.routes.last.routerName == '**' ? route.currentModule?.routes.last : null; } else { - finded = route.currentModule?.routes.last.routerName == '**' ? route.currentModule?.routes.last : null; + found = route.children.last.routerName == '**' ? route.children.last : null; + } + if(route.routerName == '/') { + break; } - route.currentModule?.paths.remove(localPath); + } + + if(found != null) { break; - } else { - segments.removeLast(); } + pathSegments.removeLast(); } - return finded?.routerName == '**' ? finded : null; + return found?.routerName == '**' ? found : null; } Future selectRoute(String path, {Module? module, dynamic arguments}) async { From 9e8c44696abb375a312f7799cd79dfe738f917b3 Mon Sep 17 00:00:00 2001 From: felipe-labbits Date: Tue, 29 Jun 2021 12:31:07 -0300 Subject: [PATCH 3/3] Fix: Do not keep searching for RouterOutlets --- .../navigation/modular_route_information_parser.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart b/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart index 233b089e..27d24301 100644 --- a/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart +++ b/flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart @@ -220,9 +220,9 @@ class ModularRouteInformationParser extends RouteInformationParser found = route.currentModule?.routes.last.routerName == '**' ? route.currentModule?.routes.last : null; } else { found = route.children.last.routerName == '**' ? route.children.last : null; - } - if(route.routerName == '/') { - break; + if(route.routerName != '/') { + break; + } } }