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: Path resolution strategy for Flutter Web hosted outside of base path (issue #941) #942

Merged
merged 3 commits into from
May 23, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,11 +2,26 @@

import 'dart:html';

import 'package:flutter_modular/flutter_modular.dart';
import 'package:flutter_web_plugins/url_strategy.dart';

import 'url_service.dart';

class WebUrlService extends UrlService {
@override
String? getPath() => resolvePath(window.location.href);
String? getPath() {
final href = window.location.href;

if (urlStrategy is HashUrlStrategy) {
if (href.endsWith(Modular.initialRoute)) {
return Modular.initialRoute;
} else if (href.contains('#')) {
return href.split('#').last;
}
}

return resolvePath(href);
}
}

UrlService create() {
Expand Down
2 changes: 2 additions & 0 deletions flutter_modular/pubspec.yaml
Expand Up @@ -12,6 +12,8 @@ dependencies:
result_dart: ">=1.0.4 <2.0.0"
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter

dev_dependencies:
flutterando_analysis: ^0.0.2
Expand Down