Skip to content
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

Rewritten paths cause a client side redirect unexpectedly when set up with basePath: false and an active basePath #65062

Open
mareksuscak opened this issue Apr 25, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.

Comments

@mareksuscak
Copy link

mareksuscak commented Apr 25, 2024

Link to the code that reproduces this issue

https://github.com/mareksuscak/router-bug/blob/main/next.config.mjs#L5-L18

To Reproduce

  1. Start the application in development mode (next dev)
  2. Navigate to http://localhost:3000/destination

Current vs. Expected behavior

Expected: page is displayed and the address bar in the browser reads /destination, not /prefix/destination
Current: page is displayed and the address bar in the browser reads /prefix/destination, not /destination

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.22
  pnpm: 8.15.5
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.0
  react-dom: 18.3.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Pages 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

I tested latest canary release 14.3.0-canary.23 and the bug is still present there. It's been happening for months. What's interesting is that this seems to be a client-side triggered redirect because the server returns HTTP 200 initially and the path changes in the browser right after. I've also tried writing a middleware to handle the rewrite instead of using rewrites in the config and it's still happening - likely a bug in the client side routing code. Here's the middleware I tried:

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
  if (request.nextUrl.pathname.startsWith('/destination')) {
    return NextResponse.rewrite(new URL('/prefix/destination', request.url))
  }
}
@mareksuscak mareksuscak added the bug Issue was opened via the bug report template. label Apr 25, 2024
@github-actions github-actions bot added the Pages Router Related to Pages Router. label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

1 participant