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

redirect() function doesn't consider basePath #54163

Closed
1 task done
XDean opened this issue Aug 17, 2023 · 5 comments · Fixed by #54277
Closed
1 task done

redirect() function doesn't consider basePath #54163

XDean opened this issue Aug 17, 2023 · 5 comments · Fixed by #54277
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@XDean
Copy link

XDean commented Aug 17, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Enterprise
    Binaries:
      Node: 16.15.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.17-canary.2
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
    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/XDean/next-bug/tree/redirect-function-basepath

To Reproduce

  • Goto /dev/redirect
  • It redirect to /target. The correct path should be /dev/target

Describe the Bug

The redirect function should consider basePath config. But it not.

Another strange behavior is, If you access /dev/link , click the link redirect to /direct, it works.

Expected Behavior

redirect('/target) can goto /dev/target

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1529

@XDean XDean added the bug Issue was opened via the bug report template. label Aug 17, 2023
@kmvan
Copy link

kmvan commented Aug 18, 2023

I don't think this is a bug.

@XDean
Copy link
Author

XDean commented Aug 18, 2023

I don't think this is a bug.

Please give some reason.

Someone may say 'this is by design', I prepared another testcase.

  • goto /dev/link
  • clik the link redirect to /direct, it works
  • right click the link redirect to /direct, open in new tab, it fails.

The behavior is not consistent.

@timneutkens
Copy link
Member

This is definitely a bug 👍

@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label Aug 18, 2023
@kmvan
Copy link

kmvan commented Aug 19, 2023

@XDean You are right.

@huozhi huozhi self-assigned this Aug 19, 2023
@kodiakhq kodiakhq bot closed this as completed in #54277 Aug 20, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 20, 2023
### What & Why
Add base path handling for the url in redirect error if the `basePath` is configured.

This is only break for server rendering case as the `basePath` is missing in the `Location` header. When running `next build`, everything is managed well with app router and base path on client side so it didn't break.

### How

Adding `basePath` if it's presented for `Location` header.
Update the `RenderOpts` type as basePath is already passed down in it, also update them for turbopack entries

Fixes #54163
Closes NEXT-1529
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2023

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.

@github-actions github-actions bot added the locked label Sep 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants