Fix state legislative tracker deep links returning 404#912
Fix state legislative tracker deep links returning 404#912SakshiKekre wants to merge 3 commits intomainfrom
Conversation
Add beforeFiles rewrites so tracker deep links like /us/state-legislative-tracker/MN/mn-hf4621 are served directly from Modal instead of through an iframe. The tracker's client-side router handles the path on page load. Previously, only /_tracker/* asset paths were rewritten. The tracker page itself was served via iframe through the [slug] route, which only matches a single path segment — deep links with state/bill sub-paths returned 404. Fixes #911
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Replace the rewrite approach with a catch-all route that preserves the iframe wrapper (header/footer). The tracker app doesn't have its own header, so serving it directly via rewrite would lose navigation chrome. Changes: - Add [countryId]/[slug]/[...rest]/page.tsx catch-all route - Add subPath prop to AppClient, appended to iframe src URL - Revert the beforeFiles rewrite from previous commit When someone pastes /us/state-legislative-tracker/MN/mn-hf4621, the catch-all matches, passes subPath="/MN/mn-hf4621" to AppClient, which appends it to the iframe src. The tracker SPA loads at that path and its client-side router shows the right bill.
The pre-built [slug] static page takes priority over the [..rest] catch-all, so the server-side subPath prop never arrives. Instead, derive the sub-path from usePathname() on the client — this always returns the full browser URL regardless of which route matched.
|
This approach (catch-all route + client-side sub-path derivation) had reliability issues on preview testing — double-loads, broken back button, and deep links still not resolving correctly. The root cause is that the iframe + postMessage + replaceState architecture fundamentally creates URLs the server can't serve. PR #914 takes a different approach: switches the tracker from iframe to a Vercel rewrite, matching how all other external apps (KYPA, WATCA, Oregon Kicker, etc.) are already served. Deep links work natively because the tracker SPA loads for any path. #914 should be merged instead of this PR. Keeping this PR open for reference in case we need to revisit the iframe approach. |
Status: SUPERSEDED by #914
This PR attempted to fix tracker deep links by keeping the iframe and deriving the sub-path client-side. It had reliability issues:
PR #914 takes a simpler approach — switching from iframe to Vercel rewrite — which fixes deep links natively.
Original approach (for reference)
Added a catch-all route
[countryId]/[slug]/[...rest]/page.tsxand modifiedAppClientto derive the sub-path fromusePathname()client-side. The pre-built[slug]static page takes priority over the catch-all in Next.js, so the server-sidesubPathprop never reached the client. The client-side derivation partially worked but caused iframe reload cascades due to the postMessage URL sync mechanism.