Skip to content

Commit 7dba762

Browse files
authored
Merge 9e8c446 into 12f7eb1
2 parents 12f7eb1 + 9e8c446 commit 7dba762

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

flutter_modular/lib/src/presenters/navigation/modular_route_information_parser.dart

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
100100
if (router != null) {
101101
router = router.copyWith(
102102
modulePath: router.modulePath == null ? '/' : tempRouteName,
103-
currentModule: route.currentModule,
103+
currentModule: router.currentModule ?? route.currentModule,
104104
guardedRoute: router.guardedRoute ?? route.guardedRoute,
105105
guards: [if (route.guards != null) ...route.guards!, if (router.guards != null) ...router.guards!],
106106
);
@@ -207,27 +207,32 @@ class ModularRouteInformationParser extends RouteInformationParser<ModularRoute>
207207
String path,
208208
Module module,
209209
) {
210-
ModularRoute? finded;
210+
ModularRoute? found;
211211

212-
final segments = path.split('/')..removeLast();
213-
final length = segments.length;
214-
for (var i = 0; i < length; i++) {
215-
final localPath = segments.join('/');
212+
var pathSegments = path.split('/')..removeLast();
213+
final length = pathSegments.length;
214+
for(var i = 0; i < length; i++) {
215+
final localPath = pathSegments.join('/');
216216
final route = _searchInModule(module, "", Uri.parse(localPath.isEmpty ? '/' : localPath));
217-
if (route != null) {
218-
if (route.children.isNotEmpty && route.routerName != '/') {
219-
finded = route.children.last.routerName == '**' ? route.children.last : null;
217+
218+
if(route != null) {
219+
if(route.children.isEmpty) {
220+
found = route.currentModule?.routes.last.routerName == '**' ? route.currentModule?.routes.last : null;
220221
} else {
221-
finded = route.currentModule?.routes.last.routerName == '**' ? route.currentModule?.routes.last : null;
222+
found = route.children.last.routerName == '**' ? route.children.last : null;
223+
if(route.routerName != '/') {
224+
break;
225+
}
222226
}
223-
route.currentModule?.paths.remove(localPath);
227+
}
228+
229+
if(found != null) {
224230
break;
225-
} else {
226-
segments.removeLast();
227231
}
232+
pathSegments.removeLast();
228233
}
229234

230-
return finded?.routerName == '**' ? finded : null;
235+
return found?.routerName == '**' ? found : null;
231236
}
232237

233238
Future<ModularRoute> selectRoute(String path, {Module? module, dynamic arguments}) async {

flutter_modular/test/src/presenters/navigation/modular_route_information_parse_test.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ main() {
8888
expect(route.args.fragment, 'abcd');
8989
});
9090

91-
test('should retrive Widcard route when not exist path', () async {
91+
test('should retrieve Wildcard route when not exist path', () async {
9292
final route = await parse.selectRoute('/paulo', module: ModuleMock());
9393
expect(route, isNotNull);
9494
expect(route.child!(context, ModularArguments()), isA<FlutterLogo>());
9595
});
9696

97-
test('should retrive Widcard route when path with query params doesnt exist', () async {
97+
test('should retrieve Wildcard route when path with query params doesn\'t exist', () async {
9898
final route = await parse.selectRoute('/paulo?adbc=1234', module: ModuleMock());
9999
expect(route, isNotNull);
100100
expect(route.child!(context, ModularArguments()), isA<FlutterLogo>());
101101
});
102102

103-
test('should retrive Widcard route when path with fragment doesnt exist', () async {
103+
test('should retrieve Wildcard route when path with fragment doesn\'t exist', () async {
104104
final route = await parse.selectRoute('/paulo#adbc=1234', module: ModuleMock());
105105
expect(route, isNotNull);
106106
expect(route.child!(context, ModularArguments()), isA<FlutterLogo>());
@@ -112,21 +112,21 @@ main() {
112112
});
113113

114114
group('Multi Module | ', () {
115-
test('should retrive route /mock', () async {
115+
test('should retrieve route /mock', () async {
116116
final route = await parse.selectRoute('/mock', module: ModuleMock());
117117
expect(route, isNotNull);
118118
expect(route.child!(context, ModularArguments()), isA<SizedBox>());
119119
expect(route.path, '/mock/');
120120
});
121121

122-
test('should retrive route /mock/', () async {
122+
test('should retrieve route /mock/', () async {
123123
final route = await parse.selectRoute('/mock/', module: ModuleMock());
124124
expect(route, isNotNull);
125125
expect(route.child!(context, ModularArguments()), isA<SizedBox>());
126126
expect(route.path, '/mock/');
127127
});
128128

129-
test('should retrive route /mock/list', () async {
129+
test('should retrieve route /mock/list', () async {
130130
final route = await parse.selectRoute('/mock/list', module: ModuleMock());
131131
expect(route, isNotNull);
132132
expect(route.child!(context, ModularArguments()), isA<ListView>());
@@ -201,14 +201,14 @@ main() {
201201
expect(route.args.fragment, 'abcd');
202202
});
203203

204-
test('should retrive dynamic route /mock/list/:id', () async {
204+
test('should retrieve dynamic route /mock/list/:id', () async {
205205
final route = await parse.selectRoute('/mock/list/3', module: ModuleMock());
206206
expect(route, isNotNull);
207207
expect(route.child!(context, route.args).toString(), '3');
208208
expect(route.path, '/mock/list/3');
209209
});
210210

211-
test('should retrive Widcard route when not exist path', () async {
211+
test('should retrieve Wildcard route when not exist path', () async {
212212
final route = await parse.selectRoute('/mock/paulo', module: ModuleMock());
213213
expect(route, isNotNull);
214214
expect(route.child!(context, ModularArguments()), isA<FlutterLogo>());
@@ -232,7 +232,7 @@ main() {
232232
});
233233

234234
group('Outlet Module | ', () {
235-
test('should retrive route /home/tab1', () async {
235+
test('should retrieve route /home/tab1', () async {
236236
final route = await parse.selectRoute('/home/tab1', module: ModuleMock());
237237
expect(route, isNotNull);
238238
expect(route.child!(context, ModularArguments()), isA<Scaffold>());
@@ -241,7 +241,7 @@ main() {
241241
expect(route.routerOutlet[0].child!(context, ModularArguments()), isA<TextField>());
242242
expect(route.routerOutlet[0].path, '/home/tab1');
243243
});
244-
test('should retrive route /home/tab2/:id', () async {
244+
test('should retrieve route /home/tab2/:id', () async {
245245
final route = await parse.selectRoute('/home/tab2/3', module: ModuleMock());
246246
expect(route, isNotNull);
247247
expect(route.child!(context, ModularArguments()), isA<Scaffold>());
@@ -254,7 +254,7 @@ main() {
254254
expect(parse.selectRoute('/home/tab3', module: ModuleMock()), throwsA(isA<ModularError>()));
255255
});
256256

257-
test('should retrive route (Module)', () async {
257+
test('should retrieve route (Module)', () async {
258258
final route = await parse.selectRoute('/mock/home', module: ModuleMock());
259259
expect(route, isNotNull);
260260
expect(route.child!(context, ModularArguments()), isA<SizedBox>());

0 commit comments

Comments
 (0)