Skip to content

Commit f60fdbe

Browse files
author
wangchunji
committed
refactor(路由): 优化路由解析逻辑,避免重复查找
将 tasks 路由的查找结果缓存到变量中,避免在多个分支中重复执行相同的查找操作,提高代码可读性和性能。
1 parent d2513a3 commit f60fdbe

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/web/src/app/AppRouter.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* @Author: wangchunji
3+
* @Date: 2026-03-19 09:57:44
4+
* @LastEditors: wangchunji
5+
* @LastEditTime: 2026-03-25 10:54:50
6+
* @Description:
7+
*/
18
import { Suspense, useEffect, useSyncExternalStore } from 'react';
29

310
import { getCurrentAppPath, navigate, subscribeNavigation } from '@shared/navigation';

src/web/src/app/routes.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export const appRoutes: AppRoute[] = [
7878

7979
export function resolveAppRoute(pathname: string): AppRoute {
8080
const normalizedPath = normalizeAppPath(pathname);
81+
const tasksRoute = appRoutes.find((route) => route.id === 'tasks') || appRoutes[0];
8182
const direct = appRoutes.find((route) => route.path === normalizedPath);
8283
if (direct) return direct;
8384
if (normalizedPath.startsWith('/tasks/')) {
84-
return appRoutes.find((route) => route.id === 'tasks') || appRoutes[0];
85+
return tasksRoute;
8586
}
86-
return appRoutes[0];
87+
return tasksRoute;
8788
}

0 commit comments

Comments
 (0)