Skip to content

Commit

Permalink
fix: If the url is /login/register, the system is redirected to /logi…
Browse files Browse the repository at this point in the history
…n/pwd-login by default .close #22
  • Loading branch information
mufeng889 committed Dec 10, 2024
1 parent b2f071c commit 9ddae85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/simple-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export function createRouter({ getReactRoutes, init, initRoutes, mode, opt }: Ro
if (!res) {
reactRouter.initialize();
} else {
reactRouter.initialize().navigate(resolve(res).fullPath);
const targetPath = typeof res === 'string' ? res : resolve(res).fullPath;
reactRouter.initialize().navigate(targetPath);
}
resolved(true);
})
Expand Down
2 changes: 1 addition & 1 deletion packages/simple-router/src/types/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ type PatchRoutesParams = Parameters<RemixRouter['patchRoutes']>;
export type Init = (
currentFullPath: string,
patchRoutes?: (parentId: PatchRoutesParams[0], routes: PatchRoutesParams[1]) => void
) => Promise<RouteLocationNamedRaw | null>;
) => Promise<RouteLocationNamedRaw | null | string>;
4 changes: 4 additions & 0 deletions src/router/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const init: Init = async currentFullPath => {
const isLogin = Boolean(localStg.get('token'));

if (!isLogin) {
if (currentFullPath.includes('login')) {
return currentFullPath;
}

const loginRoute: RouteKey = 'login';
const routeHome = getRouteHome(store.getState());

Expand Down

0 comments on commit 9ddae85

Please sign in to comment.