首页 > 其他分享 >Vue 路由跳转后刷新页面404解决办法

Vue 路由跳转后刷新页面404解决办法

时间:2022-11-09 14:44:05浏览次数:48  
标签:index Vue 刷新 404 mode 跳转 router 路由

第一种解决方法:
将vue路由模式mode: 'history' 修改为 mode: 'hash';
//router.js文件
const router = new Router({
//mode: 'history',
mode: 'hash',
routes: [
{ path: '/', redirect: '/login' },
{ path: '/login', component: Login },
]
})

第二种解决方法:

在服务器Nginx配置文件里,添加如下代码,再刷新就OK了;
location / {
try_files $uri $uri/ @router;
index index.html;
}

location @router {
rewrite ^.*$ /index.html last;
}

标签:index,Vue,刷新,404,mode,跳转,router,路由
From: https://www.cnblogs.com/LCLBook/p/16873631.html

相关文章