Skip to content

Commit 9ddae85

Browse files
committed
fix: If the url is /login/register, the system is redirected to /login/pwd-login by default .close #22
1 parent b2f071c commit 9ddae85

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

packages/simple-router/src/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ export function createRouter({ getReactRoutes, init, initRoutes, mode, opt }: Ro
216216
if (!res) {
217217
reactRouter.initialize();
218218
} else {
219-
reactRouter.initialize().navigate(resolve(res).fullPath);
219+
const targetPath = typeof res === 'string' ? res : resolve(res).fullPath;
220+
reactRouter.initialize().navigate(targetPath);
220221
}
221222
resolved(true);
222223
})

packages/simple-router/src/types/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ type PatchRoutesParams = Parameters<RemixRouter['patchRoutes']>;
143143
export type Init = (
144144
currentFullPath: string,
145145
patchRoutes?: (parentId: PatchRoutesParams[0], routes: PatchRoutesParams[1]) => void
146-
) => Promise<RouteLocationNamedRaw | null>;
146+
) => Promise<RouteLocationNamedRaw | null | string>;

src/router/guard/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const init: Init = async currentFullPath => {
2222
const isLogin = Boolean(localStg.get('token'));
2323

2424
if (!isLogin) {
25+
if (currentFullPath.includes('login')) {
26+
return currentFullPath;
27+
}
28+
2529
const loginRoute: RouteKey = 'login';
2630
const routeHome = getRouteHome(store.getState());
2731

0 commit comments

Comments
 (0)