From 46d877776f818c30f8269fdaa7acca5cfc3f7884 Mon Sep 17 00:00:00 2001 From: cgiuliani Date: Mon, 26 Feb 2024 13:48:32 -0500 Subject: [PATCH 1/3] fix: issue #941 --- .../infra/services/url_service/html_url_service.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart index 8019277f..8227b9da 100644 --- a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart +++ b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart @@ -6,7 +6,15 @@ import 'url_service.dart'; class WebUrlService extends UrlService { @override - String? getPath() => resolvePath(window.location.href); + String? getPath() { + final href = window.location.href; + + if (href.contains('#')) { + return href.split('#').last; + } + + return '/'; + } } UrlService create() { From 0a79c083e01f384652fa580a24c0e6355852c24d Mon Sep 17 00:00:00 2001 From: cgiuliani Date: Mon, 26 Feb 2024 14:57:32 -0500 Subject: [PATCH 2/3] fix: handle path strategy --- .../src/infra/services/url_service/html_url_service.dart | 8 ++++++-- flutter_modular/pubspec.yaml | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart index 8227b9da..5066d743 100644 --- a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart +++ b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart @@ -2,6 +2,8 @@ import 'dart:html'; +import 'package:flutter_web_plugins/url_strategy.dart'; + import 'url_service.dart'; class WebUrlService extends UrlService { @@ -9,11 +11,13 @@ class WebUrlService extends UrlService { String? getPath() { final href = window.location.href; - if (href.contains('#')) { + if (urlStrategy is PathUrlStrategy) { + return resolvePath(href); + } else if (href.contains('#')) { return href.split('#').last; } - return '/'; + return null; } } diff --git a/flutter_modular/pubspec.yaml b/flutter_modular/pubspec.yaml index 3364c7d1..a711455e 100644 --- a/flutter_modular/pubspec.yaml +++ b/flutter_modular/pubspec.yaml @@ -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 From 98c9188bea750095c43b9de92fd3552980309338 Mon Sep 17 00:00:00 2001 From: cgiuliani Date: Mon, 26 Feb 2024 15:22:00 -0500 Subject: [PATCH 3/3] fix: handle path strategy --- .../services/url_service/html_url_service.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart index 5066d743..1f38f611 100644 --- a/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart +++ b/flutter_modular/lib/src/infra/services/url_service/html_url_service.dart @@ -2,6 +2,7 @@ import 'dart:html'; +import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; import 'url_service.dart'; @@ -11,13 +12,15 @@ class WebUrlService extends UrlService { String? getPath() { final href = window.location.href; - if (urlStrategy is PathUrlStrategy) { - return resolvePath(href); - } else if (href.contains('#')) { - return href.split('#').last; + if (urlStrategy is HashUrlStrategy) { + if (href.endsWith(Modular.initialRoute)) { + return Modular.initialRoute; + } else if (href.contains('#')) { + return href.split('#').last; + } } - return null; + return resolvePath(href); } }