Sveltekit loading new page and passing data on button click

Viewed 535

I have a sveltekit app and I have to perform a simple params / data passing from one page to another. It seems simple but I am unable to find a solution. A new page should open on button or link click. The new page loaded should get all the data from current page. I want to avoid sending a request to server on page load. Because we have the data already, why send a request again for the same data.

Here is the link where I call the new page:

<li class="rounded-sm px-3 py-1 hover:bg-gray-100 cursor-pointer">
    <a href="./datatasks/{task.id}-update">Edit Task</a>
</li>

Current page has an array of tasks that needs to be sent to the {task.id}-update.svelte page.

    let tasks = []

And I would like to send the task object as well. Thank you

1 Answers

For cross-component (or cross-page, as a page is just another component) in Svelte you would use stores.

So the page with the button would populate a store, and the new page would simply read from this store.

Related