Yousuf Iqbal Hashim
Yousuf Iqbal Hashim

Reputation: 975

How to access url params in sapper outside of preload function?

In Sapper, AFAIK from documentation. The only way to access URL params are through preload() function, from which params are available inside params object.

The thing is that I want to access these params ouside of preload() function. From an eagle eye view of documentation. I don't / can't see the solution to my problem / requirement.

I have tried setting a property for url param inside data(). But it seems preload() has no access to data whether getting wise or setting wise. It is not meant for those things.

Upvotes: 8

Views: 4090

Answers (2)

Cornelius
Cornelius

Reputation: 886

<script>
import { stores } from "@sapper/app";

const { page } = stores();
const { slug } = $page.params;
</script>

https://sapper.svelte.dev/docs/#Stores

Upvotes: 11

SwaroopH
SwaroopH

Reputation: 107

If you are using v3 Svelte and latest alpha of Sapper, import page which is now provided as a store.

import { page } from '@sapper/app';

const  {slug} = $page.params;

Upvotes: 1

Related Questions