|
1 | 1 | import { lazy, Suspense } from 'react' |
2 | | -import { BrowserRouter, Navigate, Route, Routes, useLocation } from 'react-router-dom' |
| 2 | +import { BrowserRouter, Navigate, Route, Routes, useLocation, useParams } from 'react-router-dom' |
3 | 3 |
|
4 | 4 | // Homepage — eagerly imported. It's the cold-load path and the most-visited |
5 | 5 | // public surface, so it stays in the main entry chunk. |
@@ -115,6 +115,19 @@ function AuthGate({ children }: { children: JSX.Element }) { |
115 | 115 | return children |
116 | 116 | } |
117 | 117 |
|
| 118 | +// LegacyRedirect — <Navigate to="/app/resources/:id"> sends a literal ":id" |
| 119 | +// string instead of the captured route param (Navigate is dumb — it doesn't |
| 120 | +// interpolate). This wrapper reads the param and constructs the real |
| 121 | +// destination so /resources/<token> → /app/resources/<token> works. |
| 122 | +function LegacyResourceRedirect() { |
| 123 | + const { id = '' } = useParams() |
| 124 | + return <Navigate to={`/app/resources/${id}`} replace /> |
| 125 | +} |
| 126 | +function LegacyDeploymentRedirect() { |
| 127 | + const { id = '' } = useParams() |
| 128 | + return <Navigate to={`/app/deployments/${id}`} replace /> |
| 129 | +} |
| 130 | + |
118 | 131 | // AppLoadingFallback — shown while a lazy-loaded /app/* chunk is in flight. |
119 | 132 | // Tiny inline style so it renders even before the page's own CSS resolves. |
120 | 133 | // In practice this fallback is on screen for ~50-150ms on a warm cache. |
@@ -209,12 +222,16 @@ export function AppRoutes() { |
209 | 222 | </Route> |
210 | 223 |
|
211 | 224 | {/* Back-compat: every legacy unprefixed path that used to be a |
212 | | - dashboard route now redirects under /app. */} |
| 225 | + dashboard route now redirects under /app. Parameterized routes |
| 226 | + use a wrapper that interpolates the captured param — see |
| 227 | + LegacyResourceRedirect / LegacyDeploymentRedirect above |
| 228 | + (Navigate's `to` is literal, not parameterized). */} |
213 | 229 | <Route path="/resources" element={<Navigate to="/app/resources" replace />} /> |
214 | | - <Route path="/resources/:id" element={<Navigate to="/app/resources/:id" replace />} /> |
| 230 | + <Route path="/resources/:id" element={<LegacyResourceRedirect />} /> |
215 | 231 | <Route path="/deployments" element={<Navigate to="/app/deployments" replace />} /> |
216 | | - <Route path="/deployments/:id" element={<Navigate to="/app/deployments/:id" replace />} /> |
217 | | - <Route path="/stacks" element={<Navigate to="/app/stacks" replace />} /> |
| 232 | + <Route path="/deployments/:id" element={<LegacyDeploymentRedirect />} /> |
| 233 | + {/* /stacks legacy path retired with the route (b13b8ee). Falls |
| 234 | + through to the catch-all → /. */} |
218 | 235 | <Route path="/vault" element={<Navigate to="/app/vault" replace />} /> |
219 | 236 | <Route path="/team" element={<Navigate to="/app/team" replace />} /> |
220 | 237 | <Route path="/billing" element={<Navigate to="/app/billing" replace />} /> |
|
0 commit comments