-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent pages from clobbering each other (#213)
* handle redirects in layout * throw error if pages conflict with each other
- Loading branch information
1 parent
3006ee0
commit 9b99248
Showing
4 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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
12 changes: 9 additions & 3 deletions
12
apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[`docs/${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 | ||
}; | ||
} |
This file contains 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