Skip to content

Commit

Permalink
feat: 优化路由匹配方式
Browse files Browse the repository at this point in the history
  • Loading branch information
zhufengfj committed Dec 13, 2023
1 parent f6d7b80 commit 03d1a40
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/global/router/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,20 @@ const whiteList = [
'/error'
]

function includes (matched) {
for (const matchedElement of matched) {
if (whiteList.includes(matchedElement.path)) {
return true
}
}
return false
}

export const needRouterLoading = ref(false)

export const beforeEachHandler = (to, from, next) => {
if (!security.getToken()) {
if (!whiteList.includes(to.path)) {
if (!includes(to.matched)) {
needRouterLoading.value = false
next('/login')
return
Expand All @@ -103,7 +112,7 @@ export const beforeEachHandler = (to, from, next) => {
return
}

if (!whiteList.includes(to.path)) {
if (!includes(to.matched)) {
needRouterLoading.value = !happyFramework.routerInitiated
beforeInterceptor.filter(to, from, next)
} else {
Expand Down

1 comment on commit 03d1a40

@vercel
Copy link

@vercel vercel bot commented on 03d1a40 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.