zl程序教程

您现在的位置是:首页 >  前端

当前栏目

vue项目部署后刷新404_vue重载当前页面

Vue项目部署 页面 当前 刷新 重载 404
2023-06-13 09:14:44 时间

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183530.html原文链接:https://javaforall.cn