码迷,mamicode.com
首页 > Web开发 > 详细

Vue.js项目在apache服务器部署后,刷新404的问题

时间:2019-07-08 19:37:44      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:需要   outer   跳转   apach   rewrite   base   filename   -name   route   

原因是vue-router 使用了路由的 history 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面。

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

需要在服务端增加一个覆盖所有情况的候选资源:如果 URL 匹配不到任何静态资源,则应该返回同一个 index.html 页面,这个页面就是你 app 依赖的页面。

解决方案

在项目目录下新建文件.htaccess文件,内容为:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

即可解决问题

Vue.js项目在apache服务器部署后,刷新404的问题

标签:需要   outer   跳转   apach   rewrite   base   filename   -name   route   

原文地址:https://www.cnblogs.com/songyao666/p/11153066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!