How to go back to the previous page using SvelteKit? #10335
-
I'm building an app that requires a "back" button but I'm not sure what is the best way to do it. In this Stack Overflow question it shows some examples on how to do it, but I'm not exactly sure. I'm currently using the browser native Any suggestions? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
window.history.back(); |
Beta Was this translation helpful? Give feedback.
-
This will bypass the sveltekit navigation, let's say you're calling the |
Beta Was this translation helpful? Give feedback.
-
Instead you can also use <script>
import { preloadData, goto } from "$app/navigation"
let backPathname = ""
onMount(() => (backPathname = document.referrer))
</script>
<button
on:click={() => goto(backPathname)}
on:mouseover={async () => await preloadData(backPathname)}
>
go back
</button> |
Beta Was this translation helpful? Give feedback.
window.history.back();