File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 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 ) 。
You can’t perform that action at this time.
0 commit comments