@tanstack/router-core 1.146.0 → 1.146.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/router.cjs +4 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +4 -2
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +15 -2
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -1977,7 +1977,14 @@ export class RouterCore<
|
|
|
1977
1977
|
const parsed = parseHref(href, {
|
|
1978
1978
|
__TSR_index: replace ? currentIndex : currentIndex + 1,
|
|
1979
1979
|
})
|
|
1980
|
-
|
|
1980
|
+
|
|
1981
|
+
// If the href contains the basepath, we need to strip it before setting `to`
|
|
1982
|
+
// because `buildLocation` will add the basepath back when creating the final URL.
|
|
1983
|
+
// Without this, hrefs like '/app/about' would become '/app/app/about'.
|
|
1984
|
+
const hrefUrl = new URL(parsed.pathname, this.origin)
|
|
1985
|
+
const rewrittenUrl = executeRewriteInput(this.rewrite, hrefUrl)
|
|
1986
|
+
|
|
1987
|
+
rest.to = rewrittenUrl.pathname
|
|
1981
1988
|
rest.search = this.options.parseSearch(parsed.search)
|
|
1982
1989
|
// remove the leading `#` from the hash
|
|
1983
1990
|
rest.hash = parsed.hash.slice(1)
|
|
@@ -2040,12 +2047,18 @@ export class RouterCore<
|
|
|
2040
2047
|
}
|
|
2041
2048
|
|
|
2042
2049
|
if (reloadDocument) {
|
|
2043
|
-
|
|
2050
|
+
// When to is provided, always build a location to get the proper publicHref
|
|
2051
|
+
// (this handles redirects where href might be an internal path from resolveRedirect)
|
|
2052
|
+
// When only href is provided (no to), use it directly as it should already
|
|
2053
|
+
// be a complete path (possibly with basepath)
|
|
2054
|
+
if (to !== undefined || !href) {
|
|
2044
2055
|
const location = this.buildLocation({ to, ...rest } as any)
|
|
2045
2056
|
href = href ?? location.url.href
|
|
2046
2057
|
publicHref = publicHref ?? location.url.href
|
|
2047
2058
|
}
|
|
2048
2059
|
|
|
2060
|
+
// Use publicHref when available and href is not a full URL,
|
|
2061
|
+
// otherwise use href directly (which may already include basepath)
|
|
2049
2062
|
const reloadHref = !hrefIsUrl && publicHref ? publicHref : href
|
|
2050
2063
|
|
|
2051
2064
|
// Check blockers for external URLs unless ignoreBlocker is true
|