Skip to content

Commit 133d75f

Browse files
Switching between "hash" and "path" routing URL strategy (#110)
* Page route URL strategy can be changed * The same behaviour for hash and path strategies * defaultRouteUrlStrategy is hash * Index page notion
1 parent f39312b commit 133d75f

File tree

18 files changed

+127
-32
lines changed

18 files changed

+127
-32
lines changed

client/lib/main.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter_redux/flutter_redux.dart';
88
import 'package:redux/redux.dart';
9+
import 'package:url_strategy/url_strategy.dart';
910

11+
import '../utils/platform_utils_non_web.dart'
12+
if (dart.library.js) "../utils/platform_utils_web.dart";
13+
import '../utils/session_store_non_web.dart'
14+
if (dart.library.js) "../utils/session_store_web.dart";
1015
import 'controls/create_control.dart';
1116
import 'models/app_state.dart';
1217
import 'models/page_view_model.dart';
1318
import 'reducers.dart';
14-
import 'session_store/session_store.dart'
15-
if (dart.library.io) "session_store/session_store_io.dart"
16-
if (dart.library.js) "session_store/session_store_js.dart";
1719
import 'web_socket_client.dart';
1820

1921
const bool isProduction = bool.fromEnvironment('dart.vm.product');
@@ -35,6 +37,11 @@ void main([List<String>? args]) async {
3537

3638
if (kIsWeb) {
3739
debugPrint("Flet View is running in Web mode");
40+
var routeUrlStrategy = getRouteUrlStrategy();
41+
debugPrint("URL Strategy: $routeUrlStrategy");
42+
if (routeUrlStrategy == "path") {
43+
setPathUrlStrategy();
44+
}
3845
} else if ((Platform.isWindows || Platform.isMacOS || Platform.isLinux) &&
3946
!kDebugMode) {
4047
debugPrint("Flet View is running in Desktop mode");

client/lib/reducers.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ import 'package:flet_view/protocol/update_control_props_payload.dart';
77
import 'package:flet_view/web_socket_client.dart';
88
import 'package:flutter/cupertino.dart';
99

10-
import '../utils/platform_utils.dart'
11-
if (dart.library.io) "../utils/platform_utils_io.dart"
12-
if (dart.library.js) "../utils/platform_utils_js.dart";
10+
import '../utils/platform_utils_non_web.dart'
11+
if (dart.library.js) "../utils/platform_utils_web.dart";
12+
import '../utils/session_store_non_web.dart'
13+
if (dart.library.js) "../utils/session_store_web.dart";
1314
import 'actions.dart';
1415
import 'models/app_state.dart';
1516
import 'models/control.dart';
16-
import 'session_store/session_store.dart'
17-
if (dart.library.io) "session_store/session_store_io.dart"
18-
if (dart.library.js) "session_store/session_store_js.dart";
1917
import 'utils/desktop.dart';
2018
import 'utils/uri.dart';
2119

client/lib/session_store/session_store.dart

Lines changed: 0 additions & 9 deletions
This file was deleted.

client/lib/utils/platform_utils.dart

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
bool isProgressiveWebApp() {
22
return false;
33
}
4+
5+
String getRouteUrlStrategy() {
6+
return "";
7+
}

client/lib/utils/platform_utils_js.dart renamed to client/lib/utils/platform_utils_web.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ bool isProgressiveWebApp() {
55
window.matchMedia('(display-mode: fullscreen)').matches ||
66
window.matchMedia('(display-mode: minimal-ui)').matches;
77
}
8+
9+
String getRouteUrlStrategy() {
10+
var meta =
11+
document.head?.querySelector("meta[name='flet-route-url-strategy']");
12+
return meta != null ? meta.attributes["content"]! : "";
13+
}
File renamed without changes.
File renamed without changes.

client/lib/utils/uri.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import 'strings.dart';
22

33
String getWebPageName(Uri uri) {
4-
return trim(uri.path, "/");
4+
var urlPath = trim(uri.path, "/");
5+
if (urlPath != "") {
6+
var pathParts = urlPath.split("/");
7+
if (pathParts.length > 1) {
8+
urlPath = pathParts.sublist(0, 2).join("/");
9+
}
10+
}
11+
return urlPath;
512
}
613

714
String getWebSocketEndpoint(Uri uri) {

client/pubspec.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ packages:
116116
description: flutter
117117
source: sdk
118118
version: "0.0.0"
119+
flutter_web_plugins:
120+
dependency: transitive
121+
description: flutter
122+
source: sdk
123+
version: "0.0.0"
119124
http:
120125
dependency: "direct main"
121126
description:
@@ -137,6 +142,13 @@ packages:
137142
url: "https://pub.dartlang.org"
138143
source: hosted
139144
version: "3.2.0"
145+
js:
146+
dependency: transitive
147+
description:
148+
name: js
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "0.6.4"
140152
lints:
141153
dependency: transitive
142154
description:
@@ -247,6 +259,13 @@ packages:
247259
url: "https://pub.dartlang.org"
248260
source: hosted
249261
version: "1.3.0"
262+
url_strategy:
263+
dependency: "direct main"
264+
description:
265+
name: url_strategy
266+
url: "https://pub.dartlang.org"
267+
source: hosted
268+
version: "0.2.0"
250269
vector_math:
251270
dependency: transitive
252271
description:

0 commit comments

Comments
 (0)