Skip to content

Commit 49f60b2

Browse files
committed
fix(projects): fix login redirect to routeHome when routeHome of dynamic route is not same as static route. fixed #511
1 parent 425c69a commit 49f60b2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/router/guard/route.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
Router
77
} from 'vue-router';
88
import type { RouteKey, RoutePath } from '@elegant-router/types';
9+
import { getRouteName } from '@/router/elegant/transform';
910
import { useAuthStore } from '@/store/modules/auth';
1011
import { useRouteStore } from '@/store/modules/route';
1112
import { localStg } from '@/utils/storage';
@@ -150,8 +151,16 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
150151
if (!isLogin) {
151152
const loginRoute: RouteKey = 'login';
152153
const redirect = to.fullPath;
154+
const [redirectPath, redirectQuery] = redirect.split('?');
155+
const redirectName = getRouteName(redirectPath as RoutePath);
153156

154-
const query: LocationQueryRaw = to.name !== loginRoute ? { redirect } : {};
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+
}
155164

156165
const location: RouteLocationRaw = {
157166
name: loginRoute,

0 commit comments

Comments
 (0)