Parallel and Intercepting Route Modals #71586
-
I'm currently playing around with parallel and intercepting routes with the aim to have two modals for each a login and a register form. My goal is to have these setup with parallel/intercepted routes since they gracefully failback to a hard routed page for instances where the user doesn't support JavaScript. (I'm still on the fence about supporting progressive enhancement)... I'm running into an issue where if you link from one modal to another modal, the first modal remains on the screen. For example, you have a link from your login form to the registration page. To add to this problem, from any of the modals, if you click on a link to the parent URL (ie '/' if your route is '/login') the url will change, but the modal will remain on screen. I setup a sandbox that demonstrates this error. https://codesandbox.io/p/devbox/parallel-modal-test-wfqym4 Has anyone found a way around this or maybe a different pattern / flow that doesn't run into this issue? I'm thinking for now, just limit the modal to the login form and not the registration form. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
In this code, RootLayout always renders the children and two modals (pageonemodal, pagetwomodal). However, if you want each modal to appear differently when the route is /pageone or /pagetwo, with the current structure, both modals can be rendered simultaneously. Use conditional rendering. your code// app/layout.tsx
{pageonemodal}
{pagetwomodal} change code// app/layout.tsx
import { useRouter } from "next/router";
...
const router = useRouter();
...
{router.pathname === "/pageone" && pageonemodal}
{router.pathname === "/pagetwo" && pagetwomodal} |
Beta Was this translation helpful? Give feedback.
-
For anyone having this issue, here is what I've learned to get this to work.
The sandbox is updated to reflect these changes. |
Beta Was this translation helpful? Give feedback.
For anyone having this issue, here is what I've learned to get this to work.