Skip to content

Commit ad8bae9

Browse files
committed
handle redirects in layout
1 parent c345928 commit ad8bae9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { docs } from '$lib/server/content';
2+
import { redirect } from '@sveltejs/kit';
23
import { error } from '@sveltejs/kit';
34

45
export const prerender = true;
56

67
export async function load({ params }) {
7-
const page = docs.topics[params.path.split('/')[0]];
8+
const topic = params.path.split('/')[0];
9+
const document = docs.topics[topic];
810

9-
if (!page) {
11+
if (!document) {
1012
error(404, 'Not found');
1113
}
1214

15+
if (params.path === topic) {
16+
redirect(307, `/${document.children[0].children[0].slug}`);
17+
}
18+
1319
return {
14-
sections: page.children
20+
sections: document.children
1521
};
1622
}

apps/svelte.dev/src/routes/docs/[...path]/+page.server.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { docs } from '$lib/server/content';
22
import { render_content } from '$lib/server/renderer';
3-
import { error, redirect } from '@sveltejs/kit';
3+
import { error } from '@sveltejs/kit';
44

55
export async function load({ params }) {
66
const document = docs.pages[params.path];
77

88
if (!document) {
9-
const topic = docs.topics[params.path];
10-
if (topic) {
11-
redirect(307, `/${topic.children[0].children[0].slug}`);
12-
}
139
error(404);
1410
}
1511

0 commit comments

Comments
 (0)