Skip to content

Conversation

@denesbeck
Copy link

@denesbeck denesbeck commented Oct 25, 2025

GH issue: #85267

Summary

Add basePath support to redirect functions

Changes

This PR modifies the redirect() and permanentRedirect() functions to automatically prepend the basePath (configured in next.config.js) to relative redirect URLs.

Implementation

  • Added getBasePath() function: Retrieves the basePath from process.env.__NEXT_ROUTER_BASEPATH
  • Added prependBasePath() helper: Safely combines basePath with redirect URLs while handling edge cases:
    • Skips absolute URLs (with http:// or https://)
    • Prevents duplicate basePath prepending
    • Handles trailing/leading slashes correctly
  • Modified getRedirectError(): Now prepends basePath to the URL before creating the redirect error

@ijjk
Copy link
Member

ijjk commented Oct 25, 2025

Allow CI Workflow Run

  • approve CI run for commit: 2c22e8c

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@denesbeck denesbeck marked this pull request as ready for review October 25, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants