diff --git a/apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts b/apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts index 56b4c3cb0..065cc7249 100644 --- a/apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts +++ b/apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts @@ -1,16 +1,22 @@ import { docs } from '$lib/server/content'; +import { redirect } from '@sveltejs/kit'; import { error } from '@sveltejs/kit'; export const prerender = true; export async function load({ params }) { - const page = docs.topics[params.path.split('/')[0]]; + const topic = params.path.split('/')[0]; + const document = docs.topics[topic]; - if (!page) { + if (!document) { error(404, 'Not found'); } + if (params.path === topic) { + redirect(307, `/${document.children[0].children[0].slug}`); + } + return { - sections: page.children + sections: document.children }; } diff --git a/apps/svelte.dev/src/routes/docs/[...path]/+page.server.js b/apps/svelte.dev/src/routes/docs/[...path]/+page.server.js index 6f224b071..ff0def3ee 100644 --- a/apps/svelte.dev/src/routes/docs/[...path]/+page.server.js +++ b/apps/svelte.dev/src/routes/docs/[...path]/+page.server.js @@ -1,15 +1,11 @@ import { docs } from '$lib/server/content'; import { render_content } from '$lib/server/renderer'; -import { error, redirect } from '@sveltejs/kit'; +import { error } from '@sveltejs/kit'; export async function load({ params }) { const document = docs.pages[params.path]; if (!document) { - const topic = docs.topics[params.path]; - if (topic) { - redirect(307, `/${topic.children[0].children[0].slug}`); - } error(404); }