feat(docs-next): dynamically redirect section URLs to first leaf page#2238
Merged
dancormier merged 10 commits intomainfrom Apr 24, 2026
Merged
feat(docs-next): dynamically redirect section URLs to first leaf page#2238dancormier merged 10 commits intomainfrom
dancormier merged 10 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. |
dancormier
commented
Apr 14, 2026
abovedave
requested changes
Apr 15, 2026
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>
Ported from v2 Netlify.toml but not needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Without a page.server.ts at the [category] level, invalid URLs like /resourceswww rendered an empty landing page because `active` was undefined but nothing threw. Guard it explicitly so +error.svelte gets a chance to render. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Also fixes unknown category URLs (e.g.
/resourceswww) so they render the proper 404 page instead of an empty landing page.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 the first leaf descendantpackages/stacks-docs-next/src/routes/[category]/+page.server.ts(new)error(404)whenparent.activeis undefined, so unknown top-level URLs hit+error.svelteinstead of rendering an empty landing pagepackages/stacks-docs-next/_redirects/brand/,/copy/,/copy/patterns/,/system/,/system/develop/,/system/accessibility/,/system/foundation/,/system/base/,/system/forms/,/system/components/,/handbook/,/resources//assets/img/logo-stacks@2x.pngasset redirect (a leftover port from v2'snetlify.tomlthat's no longer needed)Behavior notes
The dynamic redirect lives in the
[category]/[[section]]/[subsection]route and covers sub-section URLs like/system/develop/,/copy/patterns/, etc.Bare category URLs (
/brand,/copy,/system,/handbook,/resources) are no longer redirected; they now render the category landing page provided bysrc/routes/[category]/+page.svelte, which lists child sections as cards.Testing
/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/messages/brand,/system,/copy,/handbook,/resources— should render the category landing page/resourceswwwor any other unknown top-level URL — should render the 404 error page with the SpotError404 illustrationChangeset
No changeset needed —
stacks-docs-nextis not a versioned package.