vue页面访问正常,但是一刷新就会404的问题解决办法:
1.解决方法:
将vue的路由模式 mode: 'history' 修改为 mode: 'hash'模式
//router.js文件 const router = new Router({ //mode: 'history', mode: 'hash', routes: [ { path: '/', redirect: '/login' }, { path: '/login', component: Login }, ] })
2.解决方法:
在服务器Nginx
配置文件里,添加如下代码,再刷新就OK了
location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; }