router icon indicating copy to clipboard operation
router copied to clipboard

v1.132.2 basePath is not working for browser url

Open leesb971204 opened this issue 3 months ago • 1 comments

Which project does this relate to?

Router

Describe the bug

Since that version, basepath has been replaced with the rewrite method, and it seems that the rewrite logic has been applied to basepath for backward compatibility with previous versions.

When basepath is configured the same way as in earlier versions, accessing without a basepath (e.g., http://localhost:3000) does not add the basepath to the browser URL.

Your Example Website or App

https://stackblitz.com/edit/github-lebazlff?file=src%2Froutes%2F__root.tsx

Steps to Reproduce the Bug or Issue

  1. check window.location.pathname in /home
  2. click about
  3. check window.location.pathname in /about

Expected behavior

window.location.pathname in home should be /app

Screenshots or Videos

No response

Platform

  • Router / Start Version: [e.g. 1.121.0]
  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Browser Version: [e.g. 91.1]
  • Bundler: [e.g. vite]
  • Bundler Version: [e.g. 7.0.0]

Additional context

No response

leesb971204 avatar Sep 24 '25 04:09 leesb971204

There are still issues in the newest version when using throw redirect: https://stackblitz.com/edit/github-m8qo8ju3?file=src%2Fmain.tsx

The "About" link includes the basepath but the beforeLoad redirect to /other (should be /basepath/other) omits it

reihwald avatar Dec 08 '25 15:12 reihwald

@leesb971204 see the updated stackblitz apart from the bump in versions I added the base to the vite cconfig

nlynzaad avatar Dec 20 '25 12:12 nlynzaad

@reihwald @leesb971204 I picked up some issues in the rewrite code path. @leesb971204 while it is still recommended to add the base in the vite config as this is where the application is mounted this also seems to resolve your issue.

@reihwald the fix also addresses your issue with the redirects, I've added an e2e test to this as well to ensure redirects with basePaths work as intended going forward.

nlynzaad avatar Dec 20 '25 15:12 nlynzaad