router加了mode:'history'打包发布过后路由无法访问

来源:5-2 vue-cli安装(下)

qq_大风吹_0

2017-05-24

http://szimg.mukewang.com/5924eaa9000198fc06200590.jpg

http://szimg.mukewang.com/5924eaaa0001f82128680808.jpg


写回答

1回答

fishenal

2017-05-24

根目录可以访问吗,首页。


如果可以就是server没有对html5 路由解析的问题。

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


Apache

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



解释一下: html5的路由是/user这样的路径,在页面里跳转的时候是通过往历史里塞记录同时修改url,单通过浏览器直接访问会通过apache访问/user目录下的index.html,这显然是没有的,vue程序的index.html只在根目录的index.html, 所以要通过上面的那段rewrite把路径转到根目录下的index.html。


0
0

最容易上手的Vue2.0入门实战教程

快速入门Vue2.0,组件化开发一个数字产品电商平台

3966 学习 · 999 问题

查看课程