Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to use goto() without reloading page on SvelteKit?

I have one problem: I need to add additional part to url (IE: I have /route and I need to convert it to /route/something without reloading of the page. I’ve tried to use goto(), but it reloads the page. I would be appreciate if someone could help me.

I'll excpect change url params ex: /watchlist/[lang] without reloading, if it possible, by using goto()

like image 399
oleh.lavryk Avatar asked Oct 23 '25 11:10

oleh.lavryk


1 Answers

For now, you should use History API instead of sveltekit goto() because goto() will actually navigate to the target page (trigger the load() ) while History API won't. See issue here.

window.history.replaceState(history.state, '', newURL)

Two things to note:

  1. Pass the current state as the first parameter in the replaceState() to avoid messing up sveltekit router.
  2. Make sure you do have a route for the newURL so that a page refresh won't break your app.
like image 99
A random guy Avatar answered Oct 25 '25 01:10

A random guy