原因
vue-router mode 默认为hash, 这样的url中带有#,如果把mode: 'history’就能去掉#号,也可以正常访问,但是再次刷新页面就会出现404错误。
const router = new Router({
mode: 'history'
});
之后在网上找到了另外一个解决方式,在服务器Nginx配置文件里,添加如下代码,再刷新就OK了
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
本文介绍如何在Vue项目中使用history模式替代hash模式,并通过配置Nginx服务器来解决由此产生的404错误问题。
8040

被折叠的 条评论
为什么被折叠?



