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

vue项目部署后刷新404_vue重载当前页面vue 页面访问正常 但是一刷新就会 404 的问题解决办法 第一种解决方法 将 vue 路由模式 mode history 修改为 mode hash router js 文件 const router new Router mode history mode hash routes path redirect

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

编程小号
上一篇 2025-02-11 16:40
下一篇 2025-02-25 19:01

相关推荐

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