feat(docs-next): dynamically redirect section URLs to first leaf page#2238
feat(docs-next): dynamically redirect section URLs to first leaf page#2238dancormier wants to merge 7 commits intomainfrom
Conversation
Previously, section-level URLs like /system/develop or /copy/patterns would 404 since no MD file or legacy fragment exists for them. These were handled by hardcoded Netlify _redirects entries that would drift out of sync with structure.yaml. Replace those hardcoded entries with a dynamic SvelteKit server-side redirect: when the active nav node has children (it's a section), the page server now walks to the first leaf descendant via a recursive firstLeafSlug helper and issues a 302 to that URL. The _redirects file retains only category-level redirects (e.g. /brand/, /system/) which have no matching SvelteKit route. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
✅ Deploy Preview for stacks ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Note to self: Verify that we don't need these redirects that have been removed
There was a problem hiding this comment.
I think this can go too, was also ported from v2 Netlify.toml but not needed
Stacks/packages/stacks-docs-next/_redirects
Lines 58 to 59 in e46cdec
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Summary
Replaces hardcoded Netlify
_redirectsentries for section-level URLs (e.g./system/develop/,/copy/patterns/) with a dynamic SvelteKit server-side redirect. When the active nav node has children (indicating a section rather than a leaf page), the server walks to the first leaf descendant via a recursive helper and issues a 302.This keeps redirect targets in sync with
structure.yamlautomatically — no more stale redirects when page order changes.Related Issue
STACKS-843
Changes
packages/stacks-docs-next/src/routes/[category]/[[section]]/[subsection]/+page.server.tsredirectfrom@sveltejs/kitNavItemtype and recursivefirstLeafSlug(prefix, item)helperparent.active?.items?.length > 0and redirect to first leafpackages/stacks-docs-next/_redirects/system/develop/,/system/accessibility/,/system/foundation/,/system/base/,/system/forms/,/system/components/,/copy/patterns/)/brand/,/copy/,/system/, etc.) which have no matching SvelteKit routeTesting
/system/develop— should redirect to/system/develop/using-stacks/system/accessibility— should redirect to/system/accessibility/intro/system/foundation— should redirect to/system/foundation/color-fundamentals/system/base— should redirect to/system/base/backgrounds/copy/patterns— should redirect to/copy/patterns/messagesChangeset
No changeset needed —
stacks-docs-nextis not a versioned package.