Skip to content

feat(docs-next): dynamically redirect section URLs to first leaf page#2238

Merged
dancormier merged 10 commits intomainfrom
STACKS-843/section-redirects
Apr 24, 2026
Merged

feat(docs-next): dynamically redirect section URLs to first leaf page#2238
dancormier merged 10 commits intomainfrom
STACKS-843/section-redirects

Conversation

@dancormier
Copy link
Copy Markdown
Contributor

@dancormier dancormier commented Apr 14, 2026

Summary

Replaces hardcoded Netlify _redirects entries 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.yaml automatically — no more stale redirects when page order changes.

Related Issue

STACKS-843

Changes

packages/stacks-docs-next/src/routes/[category]/[[section]]/[subsection]/+page.server.ts

  • Import redirect from @sveltejs/kit
  • Add NavItem type and recursive firstLeafSlug(prefix, item) helper
  • Before throwing 404, check parent.active?.items?.length > 0 and redirect to the first leaf descendant

packages/stacks-docs-next/src/routes/[category]/+page.server.ts (new)

  • Throws error(404) when parent.active is undefined, so unknown top-level URLs hit +error.svelte instead of rendering an empty landing page

packages/stacks-docs-next/_redirects

  • Remove the entire "Section index pages → first child" block (12 entries): /brand/, /copy/, /copy/patterns/, /system/, /system/develop/, /system/accessibility/, /system/foundation/, /system/base/, /system/forms/, /system/components/, /handbook/, /resources/
  • Remove the unused /assets/img/logo-stacks@2x.png asset redirect (a leftover port from v2's netlify.toml that'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 by src/routes/[category]/+page.svelte, which lists child sections as cards.

Testing

  • Visit /system/develop — should redirect to /system/develop/using-stacks
  • Visit /system/accessibility — should redirect to /system/accessibility/intro
  • Visit /system/foundation — should redirect to /system/foundation/color-fundamentals
  • Visit /system/base — should redirect to /system/base/backgrounds
  • Visit /copy/patterns — should redirect to /copy/patterns/messages
  • Visit /brand, /system, /copy, /handbook, /resources — should render the category landing page
  • Visit any leaf page — should render normally (no redirect loop)
  • Visit /resourceswww or any other unknown top-level URL — should render the 404 error page with the SpotError404 illustration

Changeset

No changeset needed — stacks-docs-next is not a versioned package.


This PR was generated by a developer using an AI agent with the
stacks-v3-dev skill

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>
@dancormier dancormier requested a review from a team April 14, 2026 23:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

⚠️ No Changeset found

Latest commit: 2d87487

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 14, 2026

Deploy Preview for stacks ready!

Name Link
🔨 Latest commit 2d87487
🔍 Latest deploy log https://app.netlify.com/projects/stacks/deploys/69ebab6ec4da6f000970069c
😎 Deploy Preview https://deploy-preview-2238--stacks.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dancormier dancormier marked this pull request as draft April 14, 2026 23:23
Comment thread packages/stacks-docs-next/_redirects
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
dancormier and others added 9 commits April 15, 2026 11:55
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>
@dancormier dancormier marked this pull request as ready for review April 24, 2026 17:47
@dancormier dancormier enabled auto-merge (squash) April 24, 2026 17:47
@dancormier dancormier requested a review from abovedave April 24, 2026 17:47
@dancormier dancormier disabled auto-merge April 24, 2026 17:53
@dancormier dancormier merged commit eabf3de into main Apr 24, 2026
18 checks passed
@dancormier dancormier deleted the STACKS-843/section-redirects branch April 24, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants