Svelte: How do I access route parameters in page.svelte?
Asked Answered
P

1

6

I am new to svelte. I have a route defined like this: /posts/[slug]. How do I access the slug in page.svelte file?

<script>
let slug = ...
</script>

I have tried searching online but cannot find the solution.

Pyroxenite answered 3/8, 2023 at 2:7 Comment(0)
B
10

You would use the page store, which you can use from wherever in your app (pages or components)

import { page } from '$app/stores';
let slug = $page.params.slug;
Burgundy answered 3/8, 2023 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.