aleph.js icon indicating copy to clipboard operation
aleph.js copied to clipboard

Feature to prevent router redirects

Open ArtemSBulgakov opened this issue 2 years ago • 3 comments
trafficstars

I use window.onbeforeunload event to prevent users from losing their form data when they try to close the page. But a user can click on <Link>, and they will be redirected to another page on the website. And there is no possibility to prevent it.

ArtemSBulgakov avatar Mar 03 '23 11:03 ArtemSBulgakov

you can create your own link, then handles the redirect with onClick event, aleph provides the redirect function for page navigation as SPA

ije avatar Mar 03 '23 11:03 ije

Ok, will use this method. Thank you!

ArtemSBulgakov avatar Mar 03 '23 11:03 ArtemSBulgakov

you can get the redirect method by using useRouter hooks:

import { useRouter } from "aleph/react"

function App(){
  const { url, redirect } = useRouter()
}

ije avatar Mar 03 '23 12:03 ije