vue 项目 页面刷新404问题

vue 项目 页面刷新404问题

OWLSAMA
2年前发布
温馨提示:
本文最后更新于2023年12月06日,已超过520天没有更新,若内容或图片失效,请留言反馈。

vue页面访问正常,但是一刷新就会404的问题解决办法:

第一种解决方法:

将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;
}


© 版权声明
THE END
喜欢就支持一下吧
点赞 0 分享 收藏
评论 抢沙发
OωO
取消