@@ -150,17 +150,7 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
150
150
// initialize the auth route requires the user to be logged in, if not, redirect to the login page
151
151
if ( ! isLogin ) {
152
152
const loginRoute : RouteKey = 'login' ;
153
- const redirect = to . fullPath ;
154
- const [ redirectPath , redirectQuery ] = redirect . split ( '?' ) ;
155
- const redirectName = getRouteName ( redirectPath as RoutePath ) ;
156
-
157
- const isRedirectHome = routeStore . routeHome === redirectName || import . meta. env . VITE_ROUTE_HOME === redirectName ;
158
-
159
- const query : LocationQueryRaw = to . name !== loginRoute && ! isRedirectHome ? { redirect } : { } ;
160
-
161
- if ( isRedirectHome && redirectQuery ) {
162
- query . redirect = `/?${ redirectQuery } ` ;
163
- }
153
+ const query = getRouteQueryOfLoginRoute ( to , routeStore . routeHome ) ;
164
154
165
155
const location : RouteLocationRaw = {
166
156
name : loginRoute ,
@@ -206,3 +196,20 @@ function handleRouteSwitch(to: RouteLocationNormalized, from: RouteLocationNorma
206
196
207
197
next ( ) ;
208
198
}
199
+
200
+ function getRouteQueryOfLoginRoute ( to : RouteLocationNormalized , routeHome : RouteKey ) {
201
+ const loginRoute : RouteKey = 'login' ;
202
+ const redirect = to . fullPath ;
203
+ const [ redirectPath , redirectQuery ] = redirect . split ( '?' ) ;
204
+ const redirectName = getRouteName ( redirectPath as RoutePath ) ;
205
+
206
+ const isRedirectHome = routeHome === redirectName ;
207
+
208
+ const query : LocationQueryRaw = to . name !== loginRoute && ! isRedirectHome ? { redirect } : { } ;
209
+
210
+ if ( isRedirectHome && redirectQuery ) {
211
+ query . redirect = `/?${ redirectQuery } ` ;
212
+ }
213
+
214
+ return query ;
215
+ }
0 commit comments