Skip to content

Commit 07d7e8b

Browse files
authored
Merge pull request #942 from savanainc/fix/941
Fix: Path resolution strategy for Flutter Web hosted outside of base path (issue #941)
2 parents 0f7f8ad + 98c9188 commit 07d7e8b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

flutter_modular/lib/src/infra/services/url_service/html_url_service.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22

33
import 'dart:html';
44

5+
import 'package:flutter_modular/flutter_modular.dart';
6+
import 'package:flutter_web_plugins/url_strategy.dart';
7+
58
import 'url_service.dart';
69

710
class WebUrlService extends UrlService {
811
@override
9-
String? getPath() => resolvePath(window.location.href);
12+
String? getPath() {
13+
final href = window.location.href;
14+
15+
if (urlStrategy is HashUrlStrategy) {
16+
if (href.endsWith(Modular.initialRoute)) {
17+
return Modular.initialRoute;
18+
} else if (href.contains('#')) {
19+
return href.split('#').last;
20+
}
21+
}
22+
23+
return resolvePath(href);
24+
}
1025
}
1126

1227
UrlService create() {

flutter_modular/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ dependencies:
1212
result_dart: ">=1.0.4 <2.0.0"
1313
flutter:
1414
sdk: flutter
15+
flutter_web_plugins:
16+
sdk: flutter
1517

1618
dev_dependencies:
1719
flutterando_analysis: ^0.0.2

0 commit comments

Comments
 (0)