From 4d5048435c5c48dad64cfbc086b1a59576bc6454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 8 Nov 2021 18:17:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20ruoyi=20=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=20=E9=85=8D=E7=BD=AE=E5=BA=94=E7=94=A8=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E8=B7=AF=E5=BE=84=E7=9A=84bug=20=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BB=9F=E4=B8=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/.env.development | 3 +++ ruoyi-ui/.env.production | 3 +++ ruoyi-ui/.env.staging | 3 +++ ruoyi-ui/src/layout/components/Navbar.vue | 2 +- ruoyi-ui/src/router/index.js | 1 - ruoyi-ui/src/utils/request.js | 2 +- ruoyi-ui/vue.config.js | 3 +-- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ruoyi-ui/.env.development b/ruoyi-ui/.env.development index 3b003aa38..4addbcd8d 100644 --- a/ruoyi-ui/.env.development +++ b/ruoyi-ui/.env.development @@ -7,6 +7,9 @@ ENV = 'development' # 若依管理系统/开发环境 VUE_APP_BASE_API = '/dev-api' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = 'http://localhost:9090/admin/login' diff --git a/ruoyi-ui/.env.production b/ruoyi-ui/.env.production index 2d0bb6184..45f4ad1ef 100644 --- a/ruoyi-ui/.env.production +++ b/ruoyi-ui/.env.production @@ -4,6 +4,9 @@ VUE_APP_TITLE = RuoYi-Vue-Plus后台管理系统 # 生产环境配置 ENV = 'production' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = '/admin/login' diff --git a/ruoyi-ui/.env.staging b/ruoyi-ui/.env.staging index 49ce55c95..ed147ca48 100644 --- a/ruoyi-ui/.env.staging +++ b/ruoyi-ui/.env.staging @@ -6,6 +6,9 @@ NODE_ENV = production # 测试环境配置 ENV = 'staging' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = '/admin/login' diff --git a/ruoyi-ui/src/layout/components/Navbar.vue b/ruoyi-ui/src/layout/components/Navbar.vue index e6721b70e..8f73e7cab 100644 --- a/ruoyi-ui/src/layout/components/Navbar.vue +++ b/ruoyi-ui/src/layout/components/Navbar.vue @@ -102,7 +102,7 @@ export default { type: 'warning' }).then(() => { this.$store.dispatch('LogOut').then(() => { - location.href = this.$router.options.base + '/index'; + location.href = process.env.VUE_APP_CONTEXT_PATH; }) }).catch(() => {}); } diff --git a/ruoyi-ui/src/router/index.js b/ruoyi-ui/src/router/index.js index cedf0b3aa..96f557b34 100644 --- a/ruoyi-ui/src/router/index.js +++ b/ruoyi-ui/src/router/index.js @@ -167,7 +167,6 @@ export const constantRoutes = [ ] export default new Router({ - base: "", // 项目前缀 与 publicPath 同步 例如 /api mode: 'history', // 去掉url中的# scrollBehavior: () => ({ y: 0 }), routes: constantRoutes diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js index e8b3b5f16..5ce0d0063 100644 --- a/ruoyi-ui/src/utils/request.js +++ b/ruoyi-ui/src/utils/request.js @@ -65,7 +65,7 @@ service.interceptors.response.use(res => { } ).then(() => { store.dispatch('LogOut').then(() => { - location.href = this.$router.options.base + '/index'; + location.href = process.env.VUE_APP_CONTEXT_PATH; }) }).catch(() => {}); return Promise.reject('无效的会话,或者会话已过期,请重新登录。') diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js index 4d6967bda..73c217777 100644 --- a/ruoyi-ui/vue.config.js +++ b/ruoyi-ui/vue.config.js @@ -16,8 +16,7 @@ module.exports = { // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 - // 设置基路径参考文档: http://doc.ruoyi.vip/ruoyi-vue/document/qdsc.html#应用路径 - publicPath: process.env.NODE_ENV === "production" ? "/" : "/", + publicPath: process.env.VUE_APP_CONTEXT_PATH, // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist) outputDir: 'dist', // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)