Skip to content

Commit c72f288

Browse files
committed
增加页面路由
1 parent 1db8d3b commit c72f288

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

multi-platforms/platform_support_of_Flutter_plugins.png renamed to platform_specific/platform_support_of_Flutter_plugins.png

File renamed without changes.

platform_specific/web/routers.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
author: 张果
3+
created_at: 2022-04-12
4+
updated_at: 2022-04-12
5+
outlines:
6+
- 为什么使用页面路由。Web平台更接近普通网页应用,方便用户通过URL访问特定页面。
7+
- Hash模式 vs Path模式(即History模式)
8+
- 使用Fluro改造路由为RESTful标准。
9+
---
10+
11+
# 页面路由设置
12+
13+
## 修改Web应用URL策略
14+
15+
[官方文档](https://flutter.dev/docs/development/ui/navigation/url-strategies)定义了两种模式:
16+
17+
- Hash模式:默认模式,带有"#"。
18+
- Path模式:不带有"#"。
19+
20+
我们需要把默认的Hash模式改为更符合正常认知的Path模式。
21+
22+
最简单的办法是使用[url_strategies](https://pub.dev/packages/url_strategy)库完成。安装库以后如下使用:
23+
24+
```dart
25+
import 'package:url_strategy/url_strategy.dart';
26+
27+
void main() {
28+
// Here we set the URL strategy for our web app.
29+
// It is safe to call this function when running on mobile or desktop as well.
30+
setPathUrlStrategy();
31+
runApp(MyApp());
32+
}
33+
```
34+
35+
关键是`setPathUrlStrategy()`,效果等同于官方文档的方法,并且不影响Mobile和Desktop应用。
36+
37+
## RESTful标准URL设置
38+
39+
需要路由的原因是,Web网站是以单页应用的形式上线的,要让它看起来像普通网页,可以用网址访问到具体资源,修改路由必不可少。
40+
41+
我们希望Flutter页面的表现尽可能符合[RESTful标准](https://restfulapi.net)
42+
43+
我们使用[`fluro`](https://pub.dev/packages/fluro)

0 commit comments

Comments
 (0)