Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 434
Yousuf Iqbal Hashim Avatar asked Apr 09 '19 13:04

Yousuf Iqbal Hashim


Video Answer


2 Answers

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

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

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

like image 71
Cornelius Avatar answered Oct 18 '22 21:10

Cornelius


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;
like image 1
SwaroopH Avatar answered Oct 18 '22 20:10

SwaroopH