Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端路由控制原理 #35

Open
Genluo opened this issue Aug 31, 2019 · 0 comments
Open

前端路由控制原理 #35

Genluo opened this issue Aug 31, 2019 · 0 comments

Comments

@Genluo
Copy link
Owner

Genluo commented Aug 31, 2019

前端路由是现代单页应用的基础,目前有两种实现思路:

  1. 基于hash的实现方式
  2. 基于H5 history的实现方式

基于HASH的实现方式

hash路由是一个带有# 的路由,我们主要是监听url中的hash变化来进行路由跳转。

监听事件:loadhashchange

优点缺点

优点是兼容性良好,缺点是URL中一直存在#,使得url不美观

基于H5 history实现方式

我们可以直接使用window.history中方法,,里面有几个方法可以实现变更url但是不刷新路由,具体的API可以参考MDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant