-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intercepting routes don’t work with route groups #53170
Comments
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here's my setup after following the docs: I basically wanted to group all settings stuff so it doesn't clutter when I'm not working on it. It should intercept and overlay on whatever's in // app/(settings)/@settings/(.)settings/page.tsx
export default function SettingsIntercept() {
console.log("SettingsIntercept!")
return (
<Modal>
<SettingsSidebar />
</Modal>
)
} Only works when I yank both |
Hi @kachkaev (and others)! Apologies for the delay in responding. Recently I've been working through the various parallel routes & interception routes issues. I took a look at the provided reproduction and I was able to get all scenarios working as expected, so I think we were able to address the problems you were running into! Scenario 1CleanShot.2024-04-23.at.17.33.11.mp4Scenario 2CleanShot.2024-04-23.at.17.34.17.mp4Scenario 3CleanShot.2024-04-23.at.17.37.17.mp4The only thing I noticed that was missing was a I'm going to close this issue, but happy to answer any additional questions, or look at other bug reproductions. Thank you! |
Hi @ztanner Thanks for your solution. Please post application file structure and maybe source code for corresponding files. I'm facing this issue and nextjs documentation doesn't give enough information. EDIT: FOUND A WORKING SOLUTION! Above solution doesn't fix this specific issue. If your route is a direct child of your route group, the only solution is to use [...catchAll]/page.tsx in the same folder as your interceptor to catch that bad boy. In my case I ended up with 2nd Edit: It would be awesome if someone could add a snippet on how to render an expected route using dynamic imports. But this solution will have to do for now. |
Can you elaborate on why this is the case? Aren't the children defined when navigating to an intercepted route? Am I missing something here? |
In the provided repro, the app transitions to a new layout (from |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 Binaries: Node: 18.16.0 npm: 9.5.1 Yarn: 1.22.19 pnpm: 8.6.10 Relevant Packages: next: 13.4.13-canary.1 eslint-config-next: 13.4.13-canary.1 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://github.com/kachkaev/next-js-intercepting-routes-in-groups-mwe
Here is the ‘product spec’:
To Reproduce
Clone the repo:
git clone https://github.com/kachkaev/next-js-intercepting-routes-in-groups-mwe.git cd next-js-intercepting-routes-in-groups-mwe pnpm install pnpm dev
Inspect the folder structure:
Here is the technical solution I have come up with based on the docs:
(no-modal)
and(with-modal)
.(with-modal)
group.@modal
which renders a photo page using an intercepting route.(no-modal)
group, together with the photo page itself.app/(with-modal)/@modal
also contains dummy routes for the home page and the ‘top photos’ page to avoid 404s. I know it is possible to adddefault
orcatch-all
routes to this folder too, but doing so would blur the distinction between the two route groups and thus make the reproduction a bit less vivid.The reproduction example does not use dynamic routes for simplicity. Photo ids are encoded in a GET param. Going for
photo/[id]
produces the same results (see below).Open http://localhost:3000 and navigate between the home page and the ‘top photos’ page. Click on individual photo links within these pages and observe them opened in the modal, as expected. We are in the same route group called
(with-modal)
, all works fine so far.happy-path.mp4
Broken scenario 1: While on a photo page, press refresh in the browser. Observe that the photo page is opened in a new page, not in a modal. This is expected. Now try navigating to a previous or a next photo and observe an error:
broken-scenario-1.mp4
Broken scenario 2: Navigate to the ‘best photo’ page and observe that it uses
(no-modal)
layout, as expected. Navigate to a photo page and observe the same error as above.broken-scenario-2.mp4
Broken scenario 3: Open the photo page and observe that it uses
(no-modal)
layout, as expected. Make a small tweak in/app/(no-modal)/photo/page.tsx
to trigger hot reloading. ObservenotFound()
error again:Describe the Bug
Seems like Next.js is unable to deal with intercepting routes and route groups at the same time. Presence of
app/(with-modal)/@modal/(...)photo/page.tsx
breaks navigation to/photo
from pages where this route is not intercepting.The same happens for dynamic routes (i.e. when
/photo?id=123
is replaced with/photo/123
). See the PR #1 in the reproduction repo.→
Expected Behavior
I would expect that the app would work according to product spec described earlier. The folder structure I have come up with seems to match Next.js docs for the listed requirements. Avoiding modals at least on the photo page is crucial and I am not sure how to do this without using route groups and intercepting routes.
Perhaps, this is just a matter of docs and I am just missing something. I have been trying various workarounds for quite a few hours last weekend but have not solved the problem no matter what I have tried. Hope that the reproduction example is helpful.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
I have not tried deploying this app yet, but if I try
pnpm build && pnpm start
, navigation remains broken in the same scenarios as duringpnpm dev
. There are two key differences:pnpm dev
, browser URL does not update when a broken link is followed.pnpm-build-start.mp4
PS: Despite this situation and some level of frustration caused by it, I find the new router pretty awesome. So let me use this bug report as an opportunity to thank the Next.js community for working on it! I know that some developers struggle with the new model because of the things they’ve got used to, but I do see a lot of value in the change! Epic stuff! 👏
The text was updated successfully, but these errors were encountered: