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

vue-router 的两种模式 #33

Open
chenyinkai opened this issue Mar 20, 2018 · 0 comments
Open

vue-router 的两种模式 #33

chenyinkai opened this issue Mar 20, 2018 · 0 comments
Labels

Comments

@chenyinkai
Copy link
Owner

hash 模式

vue router 默认模式, 格式类似于 http://localhost:8081/#/register, url 中带有 #, 使用 URLhash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载。

history 模式

history 模式就和普通的 url 一样, 通过设置 mode 的值可以改变路由模式

const router = new VueRouter({
  mode: 'history',
  routes: [...]
})

问题: 路由为 history 模式下, 当直接输入 url 访问或者刷新页面时, 会出现 404, 所以需要后台配置, 一旦 url 匹配不到任何值, 则返回到 index.html , 也就是APP.vue

location / {
  try_files $uri $uri/ /index.html;
}

以上为 nginx 配置例子

参考

https://router.vuejs.org/zh-cn/essentials/history-mode.html

@chenyinkai chenyinkai added the vue label Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant