I am using v3 and it complains if i do default export.
it says query and params doesn't exist so i can't just use them undeclared.
How do i get access to this.
Documentation for the latest Sapper updates is still a work in progress. You can follow along with it's progress in https://github.com/sveltejs/sapper/pull/638 .
To get access to the page store, which contains the objects you want, try:
<script>
import { page } from '@sapper/app';
$: console.log($page);
</script>
<p>Page URL queries:</p>
<pre>{JSON.stringify($page.query, null, 2)}</pre>
Also, the docs about how stores work is over at https://svelte.dev/docs#svelte_store
Also worth noting this might be changing with https://github.com/sveltejs/sapper/pull/642
This has changed in 0.26.0 final, and is described here
I wish the docs explained it better. I'm doing this:
import { stores } from '@sapper/app';
import HighlightedLink from '../components/HighlightedLink.svelte';
const { preloading, page, session } = stores();
const { host, path, params, query } = page;
console.log('page values', host, path, params, query);
All the values are undefined. I am trying to get to the value in the url after the segment value, like if I am on /data/abc I need the abc value. Is there a version of segment that is an array?
@jcollum page is a subscription. Try to change this line:
// Add Dollar sign before page variable
const { host, path, params, query } = $page;
host may still be undefined.. I actually don't know why that is the case, but the rest should be available to you then.
Thanks. I sorted it out and put up a gist: https://gist.github.com/jcollum/29211cf188c4174d75e2cf1a90b2cb68
Line 11 and 19 are the key lines there
Following @jcollum gist, this worked for me:
<script>
import { stores } from '@sapper/app';
const { page } = stores();
$: console.log($page.path);
</script>
Versions:
"sapper": "^0.27.0",
"svelte": "^3.0.0",
Most helpful comment
Following @jcollum gist, this worked for me:
Versions:
"sapper": "^0.27.0",
"svelte": "^3.0.0",