Toast when try change pages
Answered
Masai Lion posted this in #help-forum
Masai LionOP
My NextJS middleware redirects the user to a page if they haven't performed action x. I would like to make a toast when he tries to leave the page by clicking on any Link component, informing him that he cannot navigate.
I thought about abstracting the Link component into my own component, but I would like to know if there are other ways.
I thought about abstracting the Link component into my own component, but I would like to know if there are other ways.
Answered by Masai Lion
I need this action to be performed on any Link, creating a Link component to abstract the Next Link is my best choice so far.
2 Replies
I would extract the buttons into a client components and use useRouter to navigate
if(notcondition) return toast
return router.push("/places")
if(notcondition) return toast
return router.push("/places")
@chisto I would extract the buttons into a client components and use useRouter to navigate
if(notcondition) return toast
return router.push("/places")
Masai LionOP
I need this action to be performed on any Link, creating a Link component to abstract the Next Link is my best choice so far.
Answer