Route redirects do not respect `basePath`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/nahtnam/base-path-bug
To Reproduce
- Run the nextjs app
- Go to localhost:3000/app/home, works great (https://base-path-bug.vercel.app/app/home)
- Go to localhost:3000/app/server-component, redirects to the home perfectly (https://base-path-bug.vercel.app/app/server-component)
- Go to localhost:3000/app/route, redirects to localhost:3000/home which is a 404 (https://base-path-bug.vercel.app/app/route)
Current vs. Expected behavior
The route redirect should also go to /app/route. The docs do not indicate different behavior for different placements of redirect with the same parameters: https://nextjs.org/docs/app/api-reference/functions/redirect
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000
Binaries:
Node: 16.15.0
npm: 8.5.5
Yarn: 1.22.15
pnpm: N/A
Relevant Packages:
next: 13.5.4-canary.8
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.2.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router, Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)
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 base-path-bug reproduction and compare the redirects from /app/server-component and /app/route under the Next.js App Router. Trace the basePath handling for route redirects and add regression coverage for the failing case; done means /app/route redirects to /app/home rather than an unprefixed 404 path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100