#Closing modal (parallel route) when link navigation

4 messages · Page 1 of 1 (latest)

vernal pier
#

Hi, im suing next.js how to close a modal (using parrallel route @slot) when clicking on a link using this folder structure :

/app
layout.tsx
- /(main)
-- layout.tsx // check layout code below 
-- /(home)
--- page.tsx
-- /@modal
--- /(.)photo 
---- /[id]
----- page.tsx
-- /whatever
export default function Layout ({children, modal) {
  return (
    <div>
      {children}
       {modal}       
    <div>
  )

}

Right know if im on page.tsx in /(home) and im clicling on link <Link href='/photo/123'>link</Link> the modal is opening (normal behavior, OK).
If from this page with the opened modal im clicking on <Link href='/whatever'>link</Link> the modalis closing.
but If from /whatever I click back on home, the modal is still opened .. could help me with this ?

plucky solsticeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vernal pier
#

OK! After few days I finally foudn a workaround ! follwing this video : https://www.youtube.com/watch?v=v02LJJMz_sc

Intercepting Routes is an extremely strong concept to achieve outstanding use cases in our web apps. Sharing the modal content is one such, and this video helps you to grasp the concept with a hands-on deep dive project.

Hey, welcome back to another informative video from the "Full Stack With Next.js App Router" series. Let us build a quote fee...

▶ Play video
#

the trick is to use <dialog> tag for your modal, and then listen for route change and close it with modalRef.current.close() when leaving the route where you modal is ! hope it helps someone