RuoYi-Vue 前端分离版:部署在非根目录,刷新后出现404页面
略
·
前言
- RuoYi-Vue 3.8.4
1. 在ENV中,添加 VUE_APP_BASE_URL 配置项
- 在
.env.production
文件中添加VUE_APP_BASE_URL
配置项VUE_APP_BASE_URL = '/xxx'
。 - 在
.env.development
文件中也添加。 - 在
.env.staging
文件中也添加。
2. 在 vue.config.js 文件中,修改 publicPath 配置项
//publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
publicPath: process.env.VUE_APP_BASE_URL,
3. 在 src/utils/request.js 文件中,修改 location.href 的地址
//location.href = '/index';
location.href = process.env.VUE_APP_BASE_URL + '/index';
4. 在 src/router/index.js文件中,添加 base 配置项
export default new Router({
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
修改为:
export default new Router({
base: process.env.VUE_APP_BASE_URL,
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
5. 在 src/layout/components/Navbar.vue 文件中,修改 location.href 的地址
//location.href = "/index";
location.href = process.env.VUE_APP_BASE_URL + '/index';
6. nginx 配置中,新增一条try_files
location /xxx/ {
#root /home/ruoyi/projects/ruoyi-ui;
alias /home/ruoyi/projects/ruoyi-ui/xxx/;
try_files $uri $uri/ /xxx/index.html;
index index.html index.htm;
}
参考
更多推荐
已为社区贡献94条内容
所有评论(0)