Get params URL with Sveltekit endpoint

Viewed 1441

I'm trying to get the params in my URL for an API endpoints I coded with SvelteKit.

I wanted to use the stores for that:

import {page } from '$app/stores';

and then, in my GET endpoint:

export async function get({ request, params }) {
    const path = params.auth;
    console.log($page.URL);
…

Svelte gives me an error with: $page is not defined

Did I miss something?

1 Answers

The page store is only supposed to be used in a Svelte component. In your endpoint, the URL can be accessed via the url property on the event passed to the function.

export async function get({ request, params, url }) {
    console.log(url);
    // etc.
}
Related