Skip to content

Commit

Permalink
fix(projects): fix login redirect to routeHome when routeHome of dyna…
Browse files Browse the repository at this point in the history
…mic route is not same as static route. fixed #511
  • Loading branch information
honghuangdc committed Jun 20, 2024
1 parent 425c69a commit 49f60b2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/router/guard/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Router
} from 'vue-router';
import type { RouteKey, RoutePath } from '@elegant-router/types';
import { getRouteName } from '@/router/elegant/transform';
import { useAuthStore } from '@/store/modules/auth';
import { useRouteStore } from '@/store/modules/route';
import { localStg } from '@/utils/storage';
Expand Down Expand Up @@ -150,8 +151,16 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
if (!isLogin) {
const loginRoute: RouteKey = 'login';
const redirect = to.fullPath;
const [redirectPath, redirectQuery] = redirect.split('?');
const redirectName = getRouteName(redirectPath as RoutePath);

const query: LocationQueryRaw = to.name !== loginRoute ? { redirect } : {};
const isRedirectHome = routeStore.routeHome === redirectName || import.meta.env.VITE_ROUTE_HOME === redirectName;

const query: LocationQueryRaw = to.name !== loginRoute && !isRedirectHome ? { redirect } : {};

if (isRedirectHome && redirectQuery) {
query.redirect = `/?${redirectQuery}`;
}

const location: RouteLocationRaw = {
name: loginRoute,
Expand Down

0 comments on commit 49f60b2

Please sign in to comment.