Keep intercepting parallel route modal after hard-refresh
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hey everyone! 👋
I am trying to keep a modal open using intercepting routes and parallel routes even after a browser hard-refresh. One of my goals is to be able to share the URL and for it to show the open modal.
I leave the following repo as a starting point to understand the situation and be able to test: https://github.com/vercel/nextgram
Does anyone have any ideas on how to solve this problem?
I am trying to keep a modal open using intercepting routes and parallel routes even after a browser hard-refresh. One of my goals is to be able to share the URL and for it to show the open modal.
I leave the following repo as a starting point to understand the situation and be able to test: https://github.com/vercel/nextgram
Does anyone have any ideas on how to solve this problem?
36 Replies
Spectacled bearOP
I suppose no one has any idea : )
Northeast Congo Lion
i am facing the same problem. have u found any solution?
Well, the last time I read the docs I remember that modals only show up when you’re navigating to a page on a soft navigation, meaning you’re using a <Link> component or router.push()
If you do a hard navigation, either via typing the URL by hand on the browser or clicking a traditional link that takes you there, or a <a> tag it will not show the modal
If you do a hard navigation, either via typing the URL by hand on the browser or clicking a traditional link that takes you there, or a <a> tag it will not show the modal
Intercepting routes are a Next.js feature, Next.js can only intercept the route if the request comes from Next.js APIs ( like I said <Link> and router.push).
What Next.js does under the hood is hiding the new URL behind the current URL, it’s masking it behind the scenes so you don’t realize that the modal it’s actually a new page, if you refresh it’ll fallback to the original view, which is the full page.. maybe I wasn’t clear enough lol
What Next.js does under the hood is hiding the new URL behind the current URL, it’s masking it behind the scenes so you don’t realize that the modal it’s actually a new page, if you refresh it’ll fallback to the original view, which is the full page.. maybe I wasn’t clear enough lol
@Northeast Congo Lion i am facing the same problem. have u found any solution?
^^^ Forgot to reply to your message, you won’t get the notification so I’m replying to it now haha my bad
Northeast Congo Lion
thanks 😄 ❤️ actually i had opened this issue and waiting for the response 😄 😄
u were clear and that's what i know
so this way of creating modals is not always usefull
which strategy do you prefer? having modals logic in global state or opening it with url? "?modalOpen="true"
@Luis ^^^ Forgot to reply to your message, you won’t get the notification so I’m replying to it now haha my bad
Northeast Congo Lion
i also forget to reply 😄
@Northeast Congo Lion so this way of creating modals is not always usefull
It’s not a way of creating modals, I like to see it just a progressive enhancement NEXTJS does for you to improve some use-cases and user experiences.
@Northeast Congo Lion which strategy do you prefer? having modals logic in global state or opening it with url? "?modalOpen="true"
I like the URL method, that way if you share the URL you get the modal right away. But if it’s a modal you only want to show for some specific interaction you could simply keep it in state
Or both, synchronized. You can use a library called “nuqs” is great.
If you’re using server components stick to URL, for client stuff you can use nuqs since it works via hooks and state
If you’re using server components stick to URL, for client stuff you can use nuqs since it works via hooks and state
Northeast Congo Lion
thanks i did not know about nuqs. btw do you know any article how to create good architecture of next js app?
I’ve been trying to find the definitive one, so far I’ve been following practices from different approaches I see in GitHub open source repos
Northeast Congo Lion
yes i do the same.
Yea so far I prefer keeping things tied and close to each other, wait I have a screenshot of a project structure I liked
Northeast Congo Lion

each route folder contains its own internal
_actions
_components
_hooks
When they’re specific for that route
_actions
_components
_hooks
When they’re specific for that route
Northeast Congo Lion
i see that and you have globally used components outside the app right?
Yes exactly, my personal dev tools for example, ShadCn UI components, sometimes the page wrappers (like a <div> that takes children and set ups a max width)
@Northeast Congo Lion i see that and you have globally used components outside the app right?
For providers like theme provider or tanstack query provider or auth provider you can make a file
providers.tsx next to the root layout (layout.tsx) and simply make it take children, to keep the providers layer clean and away from the layout.tsx so it doesn’t look bloated haha
providers.tsx next to the root layout (layout.tsx) and simply make it take children, to keep the providers layer clean and away from the layout.tsx so it doesn’t look bloated haha
Northeast Congo Lion
good idea. tanstack is like react query right?
Yes, tanstack query is react query, the name changed
@Northeast Congo Lion good idea. tanstack is like react query right?
The core library name changed, the specific package you install for react apps is still called react query
Northeast Congo Lion
have u ever used swr?
i just wanna know why people prefer react query over it
@Northeast Congo Lion have u ever used swr?
I’ve never used SWR, I really like React Query tho
@Northeast Congo Lion i just wanna know why people prefer react query over it
I think it’s just because it’s more popular and it’s got more built in tooling and the API allows to you do more stuff
If you wanna learn React Query I suggest you read TKDodo blog posts, it’s the core maintainer of the library, makes GREAT content and digs into the inner details and implementations
Northeast Congo Lion
https://tkdodo.eu/blog/ these ones right?
