Skip to content

Commit 32a933d

Browse files
fix(router): update legacy URL redirects to catch-all for old paths
- Replace LegacySpecRedirect with LegacyCatchAll for improved handling of old URLs - Redirects /:specId and /:specId/:library to /python/ equivalents - Uses splat (*) to avoid route ranking conflicts with the python route group
1 parent 13a52c3 commit 32a933d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

app/src/router.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ const LazyFallback = () => (
1414
</Box>
1515
);
1616

17-
// Redirects old /:specId and /:specId/:library URLs to /python/ equivalents
18-
function LegacySpecRedirect() {
19-
const { specId, library } = useParams();
20-
return <Navigate to={specPath(specId!, library)} replace />;
17+
// Catches old URLs without /python/ prefix and redirects to /python/ equivalents.
18+
// Uses splat (*) to avoid route ranking conflicts with the python route group.
19+
function LegacyCatchAll() {
20+
const params = useParams();
21+
const splatPath = params['*'] || '';
22+
const parts = splatPath.split('/').filter(Boolean);
23+
24+
if (parts.length === 1) {
25+
return <Navigate to={specPath(parts[0])} replace />;
26+
}
27+
if (parts.length === 2) {
28+
return <Navigate to={specPath(parts[0], parts[1])} replace />;
29+
}
30+
return <NotFoundPage />;
2131
}
2232

2333
function LegacyInteractiveRedirect() {
@@ -44,10 +54,9 @@ const router = createBrowserRouter([
4454
{ path: ':specId', lazy: lazySpec },
4555
{ path: ':specId/:library', lazy: lazySpec },
4656
]},
47-
// Legacy redirects: old /:specId URLs → /python/:specId
48-
{ path: ':specId', element: <LegacySpecRedirect /> },
49-
{ path: ':specId/:library', element: <LegacySpecRedirect /> },
50-
{ path: '*', element: <NotFoundPage /> },
57+
// Legacy catch-all: redirects old /:specId and /:specId/:library to /python/ equivalents.
58+
// Uses * (lowest priority) so the python route group always wins.
59+
{ path: '*', element: <LegacyCatchAll /> },
5160
],
5261
},
5362
// Fullscreen interactive view (outside Layout)

0 commit comments

Comments
 (0)