Skip to content

Commit

Permalink
feat: ✨ 添加 Hash 路由模式
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanYi-Hui committed Dec 13, 2024
1 parent b168991 commit 2083db6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=true

# 是否开启hash路由
VITE_APP_HASH_ROUTER=false

# 是否全量引入element-plus样式
VITE_USE_ALL_ELEMENT_PLUS_STYLE=true

Expand Down
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=true

# 是否开启hash路由
VITE_APP_HASH_ROUTER=false

# 是否包分析
VITE_USE_BUNDLE_ANALYZER=false

Expand Down
3 changes: 3 additions & 0 deletions .env.gitee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=false

# 是否开启hash路由
VITE_APP_HASH_ROUTER=true

# 是否包分析
VITE_USE_BUNDLE_ANALYZER=false

Expand Down
3 changes: 3 additions & 0 deletions .env.github
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=false

# 是否开启hash路由
VITE_APP_HASH_ROUTER=true

# 是否包分析
VITE_USE_BUNDLE_ANALYZER=false

Expand Down
3 changes: 3 additions & 0 deletions .env.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=true

# 是否开启hash路由
VITE_APP_HASH_ROUTER=false

# 是否包分析
VITE_USE_BUNDLE_ANALYZER=true

Expand Down
3 changes: 3 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VITE_APP_TITLE=MicroBuild
# 是否开启动态路由
VITE_APP_DYNAMIC_ROUTER=true

# 是否开启hash路由
VITE_APP_HASH_ROUTER=false

# 是否包分析
VITE_USE_BUNDLE_ANALYZER=false

Expand Down
7 changes: 5 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { Layout, getParentLayout } from '@/utils/routerHelper'
import { NO_RESET_WHITE_LIST } from '@/constants'
Expand Down Expand Up @@ -694,7 +694,10 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
]

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
history:
import.meta.env.VITE_APP_HASH_ROUTER === 'true'
? createWebHashHistory(import.meta.env.BASE_URL)
: createWebHistory(import.meta.env.BASE_URL),
routes: constantRouterMap as RouteRecordRaw[],
scrollBehavior: () => ({ left: 0, top: 0 })
})
Expand Down

0 comments on commit 2083db6

Please sign in to comment.