Parcourir la source

feat: 如果使用 golocal 打包,则路由使用 hash 模式

yanglzh il y a 1 an
Parent
commit
c123c1bc21
3 fichiers modifiés avec 9 ajouts et 3 suppressions
  1. 3 0
      .env
  2. 3 1
      .env.golocal
  3. 3 2
      src/router/index.ts

+ 3 - 0
.env

@@ -12,6 +12,9 @@ VITE_SERVER_PROTOCOL = ''
 # 网址或ip 如 baidu.com
 VITE_SERVER_HOSTNAME = ''
 
+# 前端路由模式 hash/history
+VITE_ROUTER_MODE = 'history'
+
 # 基础服务路径
 VITE_SERVER_URL = '/base-api'
 # 基础接口路径

+ 3 - 1
.env.golocal

@@ -11,4 +11,6 @@ VITE_TOPO_URL = '/plugin/topo/'
 # modbus服务
 VITE_MODBUS_API = '/modbus'
 # ice104协议网关服务
-VITE_ICE104_API = '/ice104'
+VITE_ICE104_API = '/ice104'
+# 前端路由模式
+VITE_ROUTER_MODE = 'hash'

+ 3 - 2
src/router/index.ts

@@ -1,4 +1,4 @@
-import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
+import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router';
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import { store } from '/@/store/index';
@@ -17,7 +17,8 @@ const whiteList = ['/login', '/ssoBack']
  * @link 参考:https://next.router.vuejs.org/zh/api/#createrouter
  */
 const router = createRouter({
-	history: createWebHistory(),
+	// 如果使用 golocal 打包,则路由使用 hash 模式
+	history: import.meta.env.VITE_ROUTER_MODE === 'hash' ? createWebHashHistory() : createWebHistory(),
 	routes: staticRoutes,
 });