@@ -4,7 +4,7 @@ import { asyncRoutes, asyncRoutesByFilesystem } from './routes'
44import '@/assets/styles/nprogress.css'
55
66function setupRoutes ( router : Router ) {
7- router . beforeEach ( async ( to , _from , next ) => {
7+ router . beforeEach ( async ( to ) => {
88 const settingsStore = useSettingsStore ( )
99 const userStore = useUserStore ( )
1010 const routeStore = useRouteStore ( )
@@ -17,28 +17,20 @@ function setupRoutes(router: Router) {
1717 settingsStore . settings . menu . mode !== 'single' && menuStore . setActived ( to . path )
1818 // 如果已登录状态下,进入登录页会强制跳转到主页
1919 if ( to . name === 'login' ) {
20- next ( {
20+ return {
2121 path : settingsStore . settings . home . fullPath ,
2222 replace : true ,
23- } )
23+ }
2424 }
2525 // 如果未开启主页,但进入的是主页,则会进入侧边栏导航第一个模块
2626 else if ( ! settingsStore . settings . home . enable && to . fullPath === settingsStore . settings . home . fullPath ) {
2727 if ( menuStore . sidebarMenus . length > 0 ) {
28- next ( {
28+ return {
2929 path : menuStore . sidebarMenusFirstDeepestPath ,
3030 replace : true ,
31- } )
32- }
33- // 如果侧边栏导航第一个模块均无法命中,则还是进入主页
34- else {
35- next ( )
31+ }
3632 }
3733 }
38- // 正常访问页面
39- else {
40- next ( )
41- }
4234 }
4335 else {
4436 try {
@@ -84,58 +76,48 @@ function setupRoutes(router: Router) {
8476 userStore . logout ( )
8577 }
8678 // 动态路由生成并注册后,重新进入当前路由
87- next ( {
79+ return {
8880 path : to . path ,
8981 query : to . query ,
9082 replace : true ,
91- } )
83+ }
9284 }
9385 }
9486 else {
9587 if ( to . name !== 'login' ) {
96- next ( {
88+ return {
9789 name : 'login' ,
9890 query : {
9991 redirect : to . fullPath !== settingsStore . settings . home . fullPath ? to . fullPath : undefined ,
10092 } ,
101- } )
102- }
103- else {
104- next ( )
93+ }
10594 }
10695 }
10796 } )
10897}
10998
11099// 当父级路由未配置重定向时,自动重定向到有访问权限的子路由
111100function setupRedirectAuthChildrenRoute ( router : Router ) {
112- router . beforeEach ( ( to , _from , next ) => {
101+ router . beforeEach ( ( to ) => {
113102 const { auth } = useAuth ( )
114103 const currentRoute = router . getRoutes ( ) . find ( route => route . path === ( to . matched . at ( - 1 ) ?. path ?? '' ) )
115104 if ( ! currentRoute ?. redirect ) {
116105 const findAuthRoute = currentRoute ?. children ?. find ( route => route . meta ?. menu !== false && auth ( route . meta ?. auth ?? '' ) )
117106 if ( findAuthRoute ) {
118- next ( findAuthRoute )
107+ return findAuthRoute
119108 }
120- else {
121- next ( )
122- }
123- }
124- else {
125- next ( )
126109 }
127110 } )
128111}
129112
130113// 进度条
131114function setupProgress ( router : Router ) {
132115 const { isLoading } = useNProgress ( )
133- router . beforeEach ( ( _to , _from , next ) => {
116+ router . beforeEach ( ( ) => {
134117 const settingsStore = useSettingsStore ( )
135118 if ( settingsStore . settings . app . enableProgress ) {
136119 isLoading . value = true
137120 }
138- next ( )
139121 } )
140122 router . afterEach ( ( ) => {
141123 const settingsStore = useSettingsStore ( )
0 commit comments