@@ -12,7 +12,7 @@ function handleRouteSwitch(to: Router.Route, from: Router.Route | null) {
12
12
if ( to . handle . href ) {
13
13
window . open ( to . handle . href , '_blank' ) ;
14
14
15
- return { path : from ?. fullPath , replace : true } ;
15
+ return { path : from ?. fullPath as string , replace : true } ;
16
16
}
17
17
18
18
return null ;
@@ -80,6 +80,8 @@ const RootLayout = () => {
80
80
81
81
const routeId = useRef < string > ( null ) ;
82
82
83
+ const location = useRef < string | { path : string ; replace : boolean } | null > ( null ) ;
84
+
83
85
const { i18nKey, title } = handle ;
84
86
85
87
const { roles } = useAppSelector ( selectUserInfo ) ;
@@ -99,25 +101,22 @@ const RootLayout = () => {
99
101
if ( routeId . current !== id ) {
100
102
routeId . current = id ;
101
103
102
- const location = createRouteGuard ( route , roles , isSuper ) ;
103
-
104
- if ( location ) {
105
- if ( typeof location === 'string' ) {
106
- return < Navigate to = { location } /> ;
107
- }
108
-
109
- if ( location . path ) {
110
- return (
111
- < Navigate
112
- replace = { location . replace }
113
- to = { location . path }
114
- />
115
- ) ;
116
- }
117
- }
104
+ location . current = createRouteGuard ( route , roles , isSuper ) ;
118
105
}
119
106
120
- return < Outlet /> ;
107
+ // eslint-disable-next-line no-nested-ternary
108
+ return location . current ? (
109
+ typeof location . current === 'string' ? (
110
+ < Navigate to = { location . current } />
111
+ ) : (
112
+ < Navigate
113
+ replace = { location . current . replace }
114
+ to = { location . current . path }
115
+ />
116
+ )
117
+ ) : (
118
+ < Outlet />
119
+ ) ;
121
120
} ;
122
121
123
122
export const loader = ( ) => {
0 commit comments