Access to $page inside .ts file? #11854
-
Within onMount, I am calling a custom function, which is exported from $lib/utils:
I am calling it like so an I need to pass in the current url:
It run this exact same code on a couple of compnents and it occured to me, that doing Ideally, I'd run
It is imported alright. Ok, so I try removing the $ which changes the type script complaint to:
Is it not possible to run $page.url.pathname from $app/strores in a ts file by calling that from onMount? Do I need to make the function a front-end function somehow? I mean I am only calling it from onMount, so it should never run on the server if that's the issue |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Outside of a Svelte component you can't use the $store syntax to get the value of the page store. You could use get: import { get } from 'svelte/store';
import { page } from '$app/stores';
export function myFunction() {
let urlPath = get(page).url.pathname;
goto(urlPath)
} |
Beta Was this translation helpful? Give feedback.
Outside of a Svelte component you can't use the $store syntax to get the value of the page store. You could use get: