Skip to content

Commit ce8bae9

Browse files
author
YuChengKai
committed
路由原理
1 parent 9730d68 commit ce8bae9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Framework/framework-zh.md

+14
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,17 @@ handle() {
402402
}
403403
```
404404

405+
# 路由原理
406+
407+
前端路由实现起来其实很简单,本质就是监听 URL 的变化,然后匹配路由规则,显示相应的页面,并且无须刷新。目前单页面使用的路由就只有两种实现方式
408+
409+
- hash 模式
410+
- history 模式
411+
412+
`www.test.com/#/` 就是 Hash URL,当 `#` 后面的哈希值发生变化时,不会向服务器请求数据,可以通过 `hashchange` 事件来监听到 URL 的变化,从而进行跳转页面。
413+
414+
![](https://user-gold-cdn.xitu.io/2018/7/11/164888109d57995f?w=942&h=493&f=png&s=39581)
415+
416+
History 模式是 HTML5 新推出的功能,比之 Hash URL 更加美观
417+
418+
![](https://user-gold-cdn.xitu.io/2018/7/11/164888478584a217?w=1244&h=585&f=png&s=59637)

0 commit comments

Comments
 (0)