mirror of https://github.com/sveltejs/svelte
parent
3e1b676fec
commit
364138aba4
@ -1,7 +0,0 @@
|
||||
import { base } from '$app/paths';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').PageLoad} */
|
||||
export async function load() {
|
||||
throw redirect(307, `${base}/docs/introduction`);
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
|
||||
function getURlToRedirectTo() {
|
||||
const section = data.sections.find((val) =>
|
||||
$page.url.hash.replace('#', '').startsWith(val.path.split('/').at(-1))
|
||||
);
|
||||
|
||||
if (!section) goto('/docs/introduction');
|
||||
|
||||
// Remove the section name from hash, then redirect to that
|
||||
const hash = $page.url.hash.replace(`#${section.path.split('/').at(-1)}-`, '');
|
||||
|
||||
goto(`${section.path}#${hash}`);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
getURlToRedirectTo();
|
||||
});
|
||||
</script>
|
||||
|
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 393 B |
Loading…
Reference in new issue