Router duplicates base path when using pages with shared parent in both page and app router
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/gabrielricardourbina/nextjs-route-bug
To Reproduce
Have pages with a shared parent in both Page and App router and having a basePath
For example
.
├── pages
│ └── parent
│ └── [parentId]
│ └── child
│ ├── [childId]
│ │ └── grand-child
│ │ └── [grandChildId].tsx
│ └── [childId].tsx
└── src
└── app
└── parent
└── [parentId]
└── page.tsx
Where parent is shared in both routers
Current vs. Expected behavior
Case A from App Router to Page Router ✅
Navigating from parent/[parentId] to parent/[parentId]/child/[child] or parent/[parentId]/child/[child]/grand-child/[grandChildId], results in the respective pages being rendered and the url matching the folder structure with the basePath being prepended correctly
Case B from Page Router to App Router ✅
Navigating from parent/[parentId]/child/[child] or parent/[parentId]/child/[child]/grand-child/[grandChildId] to parent/[parentId], results the page being rendered and the url matching the folder structure with the basePath being prepended correctly
Case C from Page Router to Page Router ❌
Navigating from parent/[parentId]/child/[child] to parent/[parentId]/child/[child]/grand-child/[grandChildId] or from parent/[parentId]/child/[child]/grand-child/[grandChildId] to parent/[parentId]/child/[child], results in a redirection to a non-existing page where the basePath is duplicated I.E. /base/base/*
Video
https://github.com/user-attachments/assets/3b990434-6166-4e5d-8c2f-8d0e284bf9c4
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.2.0: Fri Dec 6 18:51:28 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8112
Available memory (MB): 24576
Available CPU cores: 8
Binaries:
Node: 18.20.2
npm: 9.9.4
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 15.1.6 // Latest available version is detected (15.1.6).
eslint-config-next: 14.2.23
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure, Pages Router, Dynamic Routes, Linking and Navigating, Redirects
Which stage(s) are affected? (Select all that apply)
Other (Deployed), next dev (local), next build (local), next start (local)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction and its pages/ and src/app/ route trees, using the shared parent, dynamic segments, and basePath described in the issue. Exercise navigation between the Page Router child and grand-child routes, then trace the routing and redirect entry points involved. Done means both directions resolve to the expected route without duplicating the base path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100