问题
Currently in having on:click | preventDefault="{() => showDetail({id})}"
and in showDetail
function i want to naviagte to particular id
which in i am passing on click of button.
I tried regular javascript methodlocation.assign
but this is reloading the page and destroying the purpose of SPA.
Is there any way to navigate in svelte without reloading
回答1:
You need a router. There are SPA routers (Single Page Application) and SSR router (Server Side Rendering).
You may try :
- https://routify.dev/
- https://github.com/EmilTholin/svelte-routing (server side)
- https://github.com/jorgegorka/svelte-router (SPA, seems not active project)
- https://github.com/ItalyPaleAle/svelte-spa-router (SPA. I recommend it)
- http://visionmedia.github.io/page.js/
- https://github.com/lukeed/navaid
- https://github.com/TehShrike/abstract-state-router/
来源:https://stackoverflow.com/questions/61888502/how-can-i-navigate-to-different-path-on-click-in-svelte