Skip to content

Commit 195f5b6

Browse files
committed
feat: enhance URL navigation for detail routes during chain switch
1 parent bd21e69 commit 195f5b6

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/hooks/ChainSyncManger.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,33 @@ export function ChainSyncManager() {
9191
const slug = getChainFromId(chainId)?.slug;
9292

9393
if (slug !== chainSlug && !isNavigating.current) {
94-
const [, ...rest] = pathname.split('/').filter(Boolean);
95-
const newPath = `/${slug}/${rest.join('/')}`;
94+
const pathSegments = pathname.split('/').filter(Boolean);
95+
96+
// Map singular detail routes to their plural list routes
97+
const detailToListRouteMap: Record<string, string> = {
98+
task: 'tasks',
99+
deal: 'deals',
100+
dataset: 'datasets',
101+
app: 'apps',
102+
workerpool: 'workerpools',
103+
address: '',
104+
tx: '',
105+
search: '',
106+
};
107+
108+
const detailRoute = pathSegments[1];
109+
const isOnDetailPage =
110+
pathSegments.length >= 3 && detailRoute in detailToListRouteMap;
111+
112+
let newPath: string;
113+
if (isOnDetailPage) {
114+
const listRoute = detailToListRouteMap[detailRoute];
115+
newPath = listRoute ? `/${slug}/${listRoute}` : `/${slug}`;
116+
} else {
117+
const [, ...rest] = pathSegments;
118+
newPath = `/${slug}/${rest.join('/')}`;
119+
}
120+
96121
isNavigating.current = true;
97122
const navigationResult = navigate({ to: newPath, replace: true });
98123
if (navigationResult instanceof Promise) {

0 commit comments

Comments
 (0)