Next.js Discord

Discord Forum

Manually closing parallell/intercepted routes

Answered
Paper wasp posted this in #help-forum
Open in Discord
Paper waspOP
Hi folks! Currently, the only way to close a modal opened via parallell/intercepted routes, is to either use router.back(), or by clicking a <Link>

Are these the only ways, or are there any other ways of doing that?

The reason router.back() doesn't work in my case, is that the modal that opens has next/forward buttons, that opens other pages in the same intercepted routes. So, router.back() will load the previous modal, and not close it. Ideally, I would like to use router.replace("/") and have the modal also close at the same time. But if I do that, the modal stays open.

Any hints or tips appreciated 😄
Answered by Ray
if you have a catch all route setup, router.replace("/") should close the modal
View full answer

8 Replies

Answer
Paper waspOP
I do have a catch all that returns null under the @modal parallell route. I'm on 14.0.5-canary.24 though, in order to include the fix from https://github.com/vercel/next.js/pull/59791. So maybe this is a new bug 🙂
ah... I had [..catchAll] instead of [...catchAll] (not enough dots!) Thanks 😄
oh lol
does it close?
Paper waspOP
yeah, it closes fine on router.push and router.replace with the catch all!
next I have to figure out how to give it a different path based on the page on where it opened... Ideally, I'd be able to somehow get the route that router.back() would navigate to on the initial load of the modal, and then cache that for the close action. But afaik there's no API for that
Paper waspOP
seems like query params is the only way to do this