Repository: next.js
Issue: Issue with Dynamic Routing Using getLayout Function in Next.js
Labels: bug

### Link to the code that reproduces this issue

[Codesandbox link](https://codesandbox.io/p/github/sebastianturbiarz/nextjs-routing-issue/main?file=%2Fsrc%2Fpages%2F_app.tsx%3A2%2C24&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522cluv8de3200063b6e8xnfdg8q%2522%252C%2522sizes%2522%253A%255B60%252C40%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522cluv8de3100023b6eaxxg1kuf%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522cluv8de3100043b6eb5mkqrg4%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522cluv8de3100053b6e6vr2s33p%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B40%252C60%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522cluv8de3100023b6eaxxg1kuf%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluv8de3100013b6e1u3b5rew%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522cluv8mwqw00023b6ese8hqp2o%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A15%252C%2522startColumn%2522%253A17%252C%2522endLineNumber%2522%253A15%252C%2522endColumn%2522%253A17%257D%255D%252C%2522filepath%2522%253A%2522%252Fpackage.json%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522cluv9yvob00023b6dmli4x7pu%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A2%252C%2522startColumn%2522%253A24%252C%2522endLineNumber%2522%253A2%252C%2522endColumn%2522%253A24%257D%255D%252C%2522filepath%2522%253A%2522%252Fsrc%252Fpages%252F_app.tsx%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522cluv8de3100023b6eaxxg1kuf%2522%252C%2522activeTabId%2522%253A%2522cluv9yvob00023b6dmli4x7pu%2522%257D%252C%2522cluv8de3100053b6e6vr2s33p%2522%253A%257B%2522id%2522%253A%2522cluv8de3100053b6e6vr2s33p%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522cluv8rsmh00c43b6enlyg26vd%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252Fmodule%252Ftest%252F1231%2522%257D%255D%252C%2522activeTabId%2522%253A%2522cluv8rsmh00c43b6enlyg26vd%2522%257D%252C%2522cluv8de3100043b6eb5mkqrg4%2522%253A%257B%2522id%2522%253A%2522cluv8de3100043b6eb5mkqrg4%2522%252C%2522activeTabId%2522%253A%2522cluv9gprv004a3b6e7ga9gkez%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluv8o4xo009j3b6e3pxxscd0%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522cluv8o554001mdchp9to62ys2%2522%257D%252C%257B%2522id%2522%253A%2522cluv9gprv004a3b6e7ga9gkez%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522cluv9gpz60029dchp8fe320i5%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D)

### To Reproduce

1. Clone the repository from this CodeSandbox link: [Codesandbox link](https://codesandbox.io/p/github/sebastianturbiarz/nextjs-routing-issue/main?file=%2Fsrc%2Fpages%2F_app.tsx%3A2%2C24&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522cluv8de3200063b6e8xnfdg8q%2522%252C%2522sizes%2522%253A%255B60%252C40%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522cluv8de3100023b6eaxxg1kuf%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522cluv8de3100043b6eb5mkqrg4%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522cluv8de3100053b6e6vr2s33p%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B40%252C60%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522cluv8de3100023b6eaxxg1kuf%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluv8de3100013b6e1u3b5rew%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522cluv8mwqw00023b6ese8hqp2o%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A15%252C%2522startColumn%2522%253A17%252C%2522endLineNumber%2522%253A15%252C%2522endColumn%2522%253A17%257D%255D%252C%2522filepath%2522%253A%2522%252Fpackage.json%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522cluv9yvob00023b6dmli4x7pu%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A2%252C%2522startColumn%2522%253A24%252C%2522endLineNumber%2522%253A2%252C%2522endColumn%2522%253A24%257D%255D%252C%2522filepath%2522%253A%2522%252Fsrc%252Fpages%252F_app.tsx%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522cluv8de3100023b6eaxxg1kuf%2522%252C%2522activeTabId%2522%253A%2522cluv9yvob00023b6dmli4x7pu%2522%257D%252C%2522cluv8de3100053b6e6vr2s33p%2522%253A%257B%2522id%2522%253A%2522cluv8de3100053b6e6vr2s33p%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522cluv8rsmh00c43b6enlyg26vd%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252Fmodule%252Ftest%252F1231%2522%257D%255D%252C%2522activeTabId%2522%253A%2522cluv8rsmh00c43b6enlyg26vd%2522%257D%252C%2522cluv8de3100043b6eb5mkqrg4%2522%253A%257B%2522id%2522%253A%2522cluv8de3100043b6eb5mkqrg4%2522%252C%2522activeTabId%2522%253A%2522cluv9gprv004a3b6e7ga9gkez%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluv8o4xo009j3b6e3pxxscd0%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522cluv8o554001mdchp9to62ys2%2522%257D%252C%257B%2522id%2522%253A%2522cluv9gprv004a3b6e7ga9gkez%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522cluv9gpz60029dchp8fe320i5%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D).
2. Navigate to a dynamic route, for example, module1/item/create.
3. From there, try navigating to another dynamic route like module1/item/some-id.
4. Notice that the page does not change to the expected dynamic page.

### Current vs. Expected behavior

Current Behavior: When navigating from module1/item/create to module1/item/some-id, the page remains on the create page.

Expected Behavior: The page should update to show the content of module1/item/some-id when navigating to this route.

### Provide environment information

```bash
Node: v20.12.0
Npm: 10.5.0
Nextjs: 13.5.6
React: 18.2.0
Typescript: 4.9.5
```


### Which area(s) are affected? (Select all that apply)

App Router

### Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

### Additional context

When I use the `getLayout` function, my dynamic pages aren't displayed correctly. Specifically, navigating between pages with similar structures causes the display to stick to the previous page's layout and content.

For example, I have two files:
1. `pages/[module]/item/create.tsx`
2. `pages/[module]/item/[id].tsx`

When navigating from `module1/item/create` to `module1/item/some-id`, the application incorrectly continues to display the 'create' page instead of switching to the 'some-id' page.

Would appreciate any guidance or suggestions on how to resolve this issue. Thank you!


Example video 

https://github.com/vercel/next.js/assets/38399239/a530c288-8546-4734-b397-1c883a60f299