Skip to content
Source
Sign inSign up
TanStack/router

fix(router-core): ensure rewrite basepath applies consistently #5202

Closedleesb971204(GitHub profile, opens in a new tab)wants to merge 24 commits intomain fromrefs/pull/5202/headopened

fixes #5200

Problem

When using the new rewrite system with basepath, redirects from / to /basepath were not working in client-side navigation.

Root Cause

The buildLocation function was returning the original fullPath for the href property instead of applying the output rewrite. This caused the Transitioner component to compare non-rewritten URLs, preventing proper redirect detection.

Summary by CodeRabbit

  • Bug Fixes

    • Links/href generation now uses the rewritten path (without origin) to prevent mixed-origin or malformed links while keeping the full rewritten URL for navigation and deep links.
  • Documentation

    • Examples updated to demonstrate the new rewrite API shape and composing rewrites; public interfaces/signatures unchanged.
  • Tests

    • Added tests validating basepath rewrite behavior and backward compatibility with basepath option.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Walkthrough

      parseLocation now sources internal href from the rewritten URL (origin removed) and sets url to the full rewritten href; publicHref remains pathname+search+hash. Documentation examples updated to use rewriteBasepath({ basepath }) and composeRewrites. Two new tests validate basepath rewrite and backward-compat behavior.

      Changes

      Cohort / File(s)Summary
      Router href & docs update
      packages/router-core/src/router.ts
      parseLocation now derives href from rewrittenUrl.href.replace(rewrittenUrl.origin, '') instead of fullPath; url uses rewrittenUrl.href; publicHref remains rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash. Examples/docs switch to rewriteBasepath({ basepath: '/basepath' }) and composeRewrites([...]). No public API signature changes.
      Tests: basepath / rewrite behavior
      packages/react-router/tests/router.test.tsx
      Added two tests verifying: (1) rewriteBasepath serves app root while browser URL retains basepath, and (2) backward-compatible basepath option produces same behavior. Tests assert rendered route and sync between router state and history pathname.

      Sequence Diagram(s)

      sequenceDiagram
        autonumber
        participant Client
        participant Router
        participant Rewriter
      
        Client->>Router: parseLocation(rawLocation)
        Router->>Rewriter: apply rewrite rules(rawLocation)
        Rewriter-->>Router: rewrittenUrl { href, origin, pathname, search, hash }
        Router->>Router: href = rewrittenUrl.href.replace(rewrittenUrl.origin, '')
        Router->>Router: url = rewrittenUrl.href
        Router->>Router: publicHref = rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash
        Router-->>Client: Location { href, url, publicHref, ... }

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      Suggested reviewers

      • Insik-Han

      Poem

      A rabbit hops through rewritten ways, I trim the origin, brighten the blaze. href now neat, url keeps the whole, publicHref shows the visible stroll. 🥕✨

      Pre-merge checks and finishing touches

      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Linked Issues Check✅ PassedThe changes implement the output rewrite of the href property in buildLocation to ensure basepath behavior and include new unit tests that verify redirects from “/” to the basepath, directly addressing the objectives of issue #5200.
      Out of Scope Changes Check✅ PassedAll modifications are confined to applying the rewrite logic in router-core and adding related tests for basepath handling, and there are no unrelated or extraneous code changes present.
      Docstring Coverage✅ PassedNo functions found in the changes. Docstring coverage check skipped.
      Title Check✅ PassedThe title adopts a conventional commit style with the scope router-core and clearly signals a bug fix. It specifies that basepath rewrites should apply consistently, directly reflecting the PR’s change to apply output rewrite to the href property in buildLocation. This mapping precisely addresses the redirect issue from '/' to '/basepath' described in issue #5200.
      ✨ Finishing touches
      • 📝 Generate Docstrings
        🧪 Generate unit tests
      • Create PR with unit tests
      • Post copyable unit tests in a comment

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      🤖 Nx Cloud AI Fix Eligible

      An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

      To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6442f7de8226a6291646a813/settings#selfHealingCISettings?utm_source=pull-request&utm_medium=comment)

      View your CI Pipeline Execution ↗ for commit 48702a462d1e53889afa51ae5d479c0e493b0c7d

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...❌ Failed10m 6sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 39sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-12-08 04:27:29 UTC

    4. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5202

      @tanstack/directive-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5202

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5202

      @tanstack/history

      npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5202

      @tanstack/nitro-v2-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5202

      @tanstack/react-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5202

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5202

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5202

      @tanstack/react-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5202

      @tanstack/react-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5202

      @tanstack/react-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5202

      @tanstack/router-cli

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5202

      @tanstack/router-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5202

      @tanstack/router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5202

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5202

      @tanstack/router-generator

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5202

      @tanstack/router-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5202

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5202

      @tanstack/router-utils

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5202

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5202

      @tanstack/server-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5202

      @tanstack/solid-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5202

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5202

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5202

      @tanstack/solid-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5202

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5202

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5202

      @tanstack/start-client-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5202

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5202

      @tanstack/start-server-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5202

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5202

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5202

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5202

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5202

      @tanstack/vue-router

      npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@5202

      @tanstack/vue-router-devtools

      npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@5202

      @tanstack/vue-router-ssr-query

      npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@5202

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5202

      commit: 48702a4

    5. Actionable comments posted: 0

      🧹 Nitpick comments (3)
      packages/router-core/src/router.ts (3)

      1683-1690: Minor: Build href from URL parts instead of stripping origin

      Safer and clearer to concatenate pathname + search + hash than using replace on href (avoids accidental substring removal if origin appears elsewhere).

      -        href: rewrittenUrl.href.replace(rewrittenUrl.origin, ''),
      +        href: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash,

      1781-1783: Align equality check with new href semantics (compare publicHref)

      buildLocation.href is now output‑rewritten while latestLocation.href (from parse) remains input‑rewritten. Comparing them will false‑negative under basepath. Compare publicHref on both sides to retain the “no-op if nothing changed” optimization.

      -    const isSameUrl =
      -      trimPathRight(this.latestLocation.href) === trimPathRight(next.href)
      +    const isSameUrl =
      +      trimPathRight(this.latestLocation.publicHref) ===
      +      trimPathRight(next.publicHref)

      1939-1945: SSR parity: compare and redirect using publicHref

      Same reasoning as above: avoid comparing input‑rewritten href to output‑rewritten href. Use publicHref for both the comparison and redirect target to prevent unnecessary redirects (or loops) when a basepath rewrite is active.

      -      if (
      -        trimPath(normalizeUrl(this.latestLocation.href)) !==
      -        trimPath(normalizeUrl(nextLocation.href))
      -      ) {
      -        throw redirect({ href: nextLocation.href })
      -      }
      +      if (
      +        trimPath(normalizeUrl(this.latestLocation.publicHref)) !==
      +        trimPath(normalizeUrl(nextLocation.publicHref))
      +      ) {
      +        throw redirect({ href: nextLocation.publicHref })
      +      }
      📜 Review details

      Configuration used: CodeRabbit UI

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 065722ab2949b1a6b8493dc288d37dfd0e19c3ff and 23be5f9d773baf950be6ddb2271f55ded775541f.

      📒 Files selected for processing (1)
      • packages/router-core/src/router.ts (1 hunks)
      🧰 Additional context used
      📓 Path-based instructions (2)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Use TypeScript in strict mode with extensive type safety across the codebase

      Files:

      • packages/router-core/src/router.ts
      packages/router-core/**

      📄 CodeRabbit inference engine (AGENTS.md)

      Keep framework-agnostic core router logic in packages/router-core/

      Files:

      • packages/router-core/src/router.ts
      ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
      • GitHub Check: Preview
      • GitHub Check: Test
    6. schiller-manuel(GitHub profile, opens in a new tab)commented

      thanks for the PR! any idea why the e2e tests fail?

      also, we should add tests for this (ideally some unit tests)

    7. thanks for the PR! any idea why the e2e tests fail?

      also, we should add tests for this (ideally some unit tests)

      I’m not really sure — honestly, I’m not very familiar with TanStack Start. When I run the Start example on my branch, the app gets stuck due to excessive redirects caused by the basepath. Do you have any idea what might be happening?

      I’ll go ahead and add a unit test in the meantime!

    8. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router

    9. Actionable comments posted: 0

      🧹 Nitpick comments (2)
      packages/react-router/tests/router.test.tsx (2)

      2701-2732: Good coverage of basepath on root; add a test for “/” → basepath redirect

      This validates internal “/” vs browser “/my-app/” when landing on “/my-app/”. To guard against regressions for the original bug (missing redirect from “/” to basepath), add a companion test starting at “/” and asserting history ends at “/my-app/” while router stays at “/”.

      Apply this diff near this test:

      +  it('should redirect from "/" to basepath and keep internal pathname "/"', async () => {
      +    const rootRoute = createRootRoute({ component: () => <Outlet /> })
      +    const indexRoute = createRoute({
      +      getParentRoute: () => rootRoute,
      +      path: '/',
      +      component: () => <div data-testid="home">Home</div>,
      +    })
      +    const routeTree = rootRoute.addChildren([indexRoute])
      +
      +    const history = createMemoryHistory({ initialEntries: ['/'] })
      +    const router = createRouter({
      +      routeTree,
      +      history,
      +      rewrite: rewriteBasepath({ basepath: '/my-app' }),
      +    })
      +
      +    render(<RouterProvider router={router} />)
      +
      +    await waitFor(() => {
      +      expect(screen.getByTestId('home')).toBeInTheDocument()
      +    })
      +
      +    expect(router.state.location.pathname).toBe('/')
      +    // Allow either trailing or non-trailing slash if normalization changes:
      +    expect(['/my-app', '/my-app/']).toContain(history.location.pathname)
      +  })

      2734-2765: Back-compat test looks good; also assert navigation applies output rewrite with basepath option

      This confirms basepath option parity on initial load. Add a navigation test mirroring the Link-based case to ensure output rewrite occurs with basepath option too.

      Apply this diff near this block:

      +  it('basepath option: Link navigation applies output rewrite', async () => {
      +    const rootRoute = createRootRoute({ component: () => <Outlet /> })
      +    const indexRoute = createRoute({
      +      getParentRoute: () => rootRoute,
      +      path: '/',
      +      component: () => (
      +        <div>
      +          <Link to="/about" data-testid="about-link">About</Link>
      +        </div>
      +      ),
      +    })
      +    const aboutRoute = createRoute({
      +      getParentRoute: () => rootRoute,
      +      path: '/about',
      +      component: () => <div data-testid="about">About</div>,
      +    })
      +    const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
      +
      +    const history = createMemoryHistory({ initialEntries: ['/my-app/'] })
      +    const router = createRouter({ routeTree, history, basepath: '/my-app' })
      +
      +    render(<RouterProvider router={router} />)
      +    const aboutLink = await screen.findByTestId('about-link')
      +    fireEvent.click(aboutLink)
      +
      +    await waitFor(() => {
      +      expect(screen.getByTestId('about')).toBeInTheDocument()
      +    })
      +    expect(router.state.location.pathname).toBe('/about')
      +    expect(history.location.pathname).toBe('/my-app/about')
      +  })
      📜 Review details

      Configuration used: CodeRabbit UI

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 593cb78e4ba6b8dc482762fed50803693870a9b3 and a9dbeb776f0be8cdaede5c419917488804384d0a.

      📒 Files selected for processing (2)
      • packages/react-router/tests/router.test.tsx (1 hunks)
      • packages/router-core/src/router.ts (2 hunks)
      🚧 Files skipped from review as they are similar to previous changes (1)
      • packages/router-core/src/router.ts
      🧰 Additional context used
      📓 Path-based instructions (2)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Use TypeScript in strict mode with extensive type safety across the codebase

      Files:

      • packages/react-router/tests/router.test.tsx
      packages/{react-router,solid-router}/**

      📄 CodeRabbit inference engine (AGENTS.md)

      Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/

      Files:

      • packages/react-router/tests/router.test.tsx
      🧬 Code graph analysis (1)
      packages/react-router/tests/router.test.tsx (5)
      packages/react-router/src/route.tsx (2)
      • createRootRoute (566-618)
      • createRoute (310-390)
      packages/react-router/src/Match.tsx (1)
      • Outlet (309-359)
      packages/history/src/index.ts (1)
      • createMemoryHistory (568-614)
      packages/react-router/src/router.ts (1)
      • createRouter (80-82)
      packages/react-router/src/RouterProvider.tsx (1)
      • RouterProvider (47-56)
      ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
      • GitHub Check: Test
      • GitHub Check: Preview
    10. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router

    11. @@ -1913,3 +1917,9 @@
      19131917 } catch {}
      19141918 }
      19151919
      1920+ const nextLocation = this.buildLocation({
      1921+ to,
      1922+ ...rest,
      1923+ _includeValidateSearch: true,
      1924+ _isNavigate: true,
      1925+ } as any)
      leesb971204(GitHub profile, opens in a new tab)commented

      Call buildLocation only once and reuse the result.

      @@ -1926,8 +1946,10 @@
      19261946 return Promise.resolve()
      19271947 }
      19281948
      1929- return this.buildAndCommitLocation({
      1930- ...rest,
      1931- href,
      1932- to: to as string,
      1933- _isNavigate: true,
      1949+ return this.commitLocation({
      1950+ ...nextLocation,
      1951+ replace: rest.replace,
      1952+ resetScroll: rest.resetScroll,
      1953+ hashScrollIntoView: rest.hashScrollIntoView,
      1954+ viewTransition: rest.viewTransition,
      1955+ ignoreBlocker: rest.ignoreBlocker,
      leesb971204(GitHub profile, opens in a new tab)commented

      Since buildLocation is always called above, only commitLocation is executed here.

      @@ -1913,3 +1917,18 @@
      19131917 } catch {}
      19141918 }
      19151919
      1920+ const nextLocation = this.buildLocation({
      1921+ to,
      1922+ ...rest,
      1923+ _includeValidateSearch: true,
      1924+ _isNavigate: true,
      1925+ } as any)
      1926+
      1927+ if (!reloadDocument) {
      1928+ const currentOrigin = new URL(this.latestLocation.url).origin
      1929+ const nextOrigin = new URL(nextLocation.url).origin
      1930+
      1931+ if (currentOrigin !== nextOrigin) {
      1932+ reloadDocument = true
      1933+ href = nextLocation.url
      1934+ }
      leesb971204(GitHub profile, opens in a new tab)commented

      Compare the origins to perform a hard navigation.

    12. @schiller-manuel

      Are there any other things we should consider?

    13. @leesb971204 Do you need help pushing this over the finish line?

    14. @leesb971204 Do you need help pushing this over the finish line?

      I’ve handled the issue in what I believe is the appropriate way and am currently waiting for a review. If there’s any additional way I can contribute, I’d be more than happy to help!

    15. @leesb971204 Do you need help pushing this over the finish line?

      I’ve handled the issue in what I believe is the appropriate way and am currently waiting for a review. If there’s any additional way I can contribute, I’d be more than happy to help!

      Maybe Manuel lost track of this PR. Have you thought about asking him on Discord?

    16. @leesb971204 Do you need help pushing this over the finish line?

      I’ve handled the issue in what I believe is the appropriate way and am currently waiting for a review. If there’s any additional way I can contribute, I’d be more than happy to help!

      Maybe Manuel lost track of this PR. Have you thought about asking him on Discord?

      Thank you for the feedback. I’ve sent a Discord message to Manuel and will wait for his response.

    17. Heard something? @leesb971204

    18. Heard something? @leesb971204

      noting 🙁

    19. nlynzaad(GitHub profile, opens in a new tab)commented

      Hi @leesb971204 there was quite a rewrite that was completed on router-core recently.

      Would you be able to merge this with the latest main?

      I just ran the tests you included, and they passed on the latest builds without any changes so not too sure if the tests aren't built from a failing initially point or if the problem has been resolved? Also took the original issue's repro, set the base in vite (to ensure its initially mounted in the correct path during dev) and did not see any specific issues.

      I'm probably missing something here, so if you could merge with the latest main and ensure failing tests before your changes are applied and then obviously succeeding after your changes.

    20. @nlynzaad

      As you suggested, I just ran the tests on both the latest main branch and a PR branch that merges in the latest main. In both cases, the tests passed successfully.

      However, when I merge main into the PR branch again, the issue reappears — even though it was previously resolved and working as expected.

      I suspect that recent changes in the core are invalidating the fix I applied earlier. I’ll need to look into it more closely, but I believe I’ll have to find a new solution and rewrite the test accordingly.

      Also, when you said that setting Vite’s base solves the issue — does that mean this work is unnecessary?

      To be honest, I don’t clearly remember whether setting only the router’s basePath (without Vite’s base) was enough to make things work. This issue has been going on for quite some time, so I’m not sure anymore whether the problem occurred because the base wasn’t set at all.

    21. nlynzaad(GitHub profile, opens in a new tab)commented

      @leesb971204 thanks for merging main into this.

      When the app is served, through vite dev or another bundler or server in prod this will load at the route it is served at.

      In vite dev's case this is by defualt at /, but can be set to /custom by configuring the base property in the vite config.

      Router needs to know if the app is served at any path other than the default /. This is to ensure navigation happens correctly at that base path.

      While it can deduce this in vite dev's case, when served from another server or bundler there is no way for Router to know what the base path is. We therefore need to do this by configuration which is done by setting the basePath property in createRouter. In other words, these needs to match.

      When updating the PR in the original issue and ensuring the app is served at the correct location I was no longer able to see a problem.

      So before any more work is done on this PR I think we need to ensure the issue this PR is trying to solve is in actual fact still occuring.

      @reihwald seeing as you are experiencing a similar issue could you please add your own reproducer onto the original issue, ensure its updated to the latest main, the app is served at the correct custom path and the basePath in router is set to match this custom path.

    22. leesb971204(GitHub profile, opens in a new tab)commented

      @leesb971204 thanks for merging main into this.

      When the app is served, through vite dev or another bundler or server in prod this will load at the route it is served at.

      In vite dev's case this is by defualt at /, but can be set to /custom by configuring the base property in the vite config.

      Router needs to know if the app is served at any path other than the default /. This is to ensure navigation happens correctly at that base path.

      While it can deduce this in vite dev's case, when served from another server or bundler there is no way for Router to know what the base path is. We therefore need to do this by configuration which is done by setting the basePath property in createRouter. In other words, these needs to match.

      When updating the PR in the original issue and ensuring the app is served at the correct location I was no longer able to see a problem.

      So before any more work is done on this PR I think we need to ensure the issue this PR is trying to solve is in actual fact still occuring.

      @reihwald seeing as you are experiencing a similar issue could you please add your own reproducer onto the original issue, ensure its updated to the latest main, the app is served at the correct custom path and the basePath in router is set to match this custom path.

      I’m really sorry for asking again, but just to confirm — If we don’t set the base in vite.config and only set basePath in the router, is it expected for useLocation().pathname or window.location.pathname to return '/' when accessed from the root path?

    23. On initial render yes. Router has not executed any navigations yet to actually update the url with the set basePath

    24. leesb971204(GitHub profile, opens in a new tab)commented

      On initial render yes. Router has not executed any navigations yet to actually update the url with the set basePath

      In that case, this PR might not be necessary — but from what I recall, before rewrite was added, the initial render would show the basePath in pathname regardless of the base setting in vite.config.

      I tested it with version 1.129.2, and it does behave that way: https://stackblitz.com/edit/github-lebazlff-9dj5638p?file=package.json,src%2Froutes%2F__root.tsx,src%2Fmain.tsx

      Below is the test case I ran using the latest version: https://stackblitz.com/edit/github-szphp94v?file=src%2Froutes%2Fabout.tsx,src%2Froutes%2F__root.tsx,src%2Froutes%2Findex.tsx

      Shouldn't both versions behave the same way?

    25. Thank you for looking into this @nlynzaad. I'm not facing the exact same issue as @leesb971204 it seems. Please take a look at https://github.com/TanStack/router/issues/5200#issuecomment-3627658496 for a reproducer for my issue. Would you agree that this is worth a different issue?

    26. @reihwald yes agreed, please create a new issue. From the description it seems related but different enough for a seperate issue

    27. leesb971204(GitHub profile, opens in a new tab)commented

      @nlynzaad

      How do you think this issue(#5200) should be handled in this PR?

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

    29. @leesb971204 I'm going to close this in favour of #6157 which is updated with the latest main and addresses the issues in rewrite and buildLocation.

Sign in to join this conversation.