How can i navigate to different path on click in svelte?

为君一笑 提交于 2021-01-29 16:37:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!