Skip to content
Merged
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 @@ -100,7 +100,7 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
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!],
);
Expand Down Expand Up @@ -207,27 +207,32 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
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<ModularRoute> selectRoute(String path, {Module? module, dynamic arguments}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlutterLogo>());
});

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<FlutterLogo>());
});

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<FlutterLogo>());
Expand All @@ -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<SizedBox>());
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<SizedBox>());
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<ListView>());
Expand Down Expand Up @@ -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<FlutterLogo>());
Expand All @@ -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<Scaffold>());
Expand All @@ -241,7 +241,7 @@ main() {
expect(route.routerOutlet[0].child!(context, ModularArguments()), isA<TextField>());
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<Scaffold>());
Expand All @@ -254,7 +254,7 @@ main() {
expect(parse.selectRoute('/home/tab3', module: ModuleMock()), throwsA(isA<ModularError>()));
});

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<SizedBox>());
Expand Down