@tanstack/router-core 1.132.26 → 1.132.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.132.26",
3
+ "version": "1.132.29",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/rewrite.ts CHANGED
@@ -23,13 +23,28 @@ export function rewriteBasepath(opts: {
23
23
  caseSensitive?: boolean
24
24
  }) {
25
25
  const trimmedBasepath = trimPath(opts.basepath)
26
- const regex = new RegExp(
27
- `^/${trimmedBasepath}/`,
28
- opts.caseSensitive ? '' : 'i',
29
- )
26
+ const normalizedBasepath = `/${trimmedBasepath}`
27
+ const normalizedBasepathWithSlash = `${normalizedBasepath}/`
28
+ const checkBasepath = opts.caseSensitive
29
+ ? normalizedBasepath
30
+ : normalizedBasepath.toLowerCase()
31
+ const checkBasepathWithSlash = opts.caseSensitive
32
+ ? normalizedBasepathWithSlash
33
+ : normalizedBasepathWithSlash.toLowerCase()
34
+
30
35
  return {
31
36
  input: ({ url }) => {
32
- url.pathname = url.pathname.replace(regex, '/')
37
+ const pathname = opts.caseSensitive
38
+ ? url.pathname
39
+ : url.pathname.toLowerCase()
40
+
41
+ // Handle exact basepath match (e.g., /my-app -> /)
42
+ if (pathname === checkBasepath) {
43
+ url.pathname = '/'
44
+ } else if (pathname.startsWith(checkBasepathWithSlash)) {
45
+ // Handle basepath with trailing content (e.g., /my-app/users -> /users)
46
+ url.pathname = url.pathname.slice(normalizedBasepath.length)
47
+ }
33
48
  return url
34
49
  },
35
50
  output: ({ url }) => {
package/src/router.ts CHANGED
@@ -2230,18 +2230,17 @@ export class RouterCore<
2230
2230
 
2231
2231
  resolveRedirect = (redirect: AnyRedirect): AnyRedirect => {
2232
2232
  if (!redirect.options.href) {
2233
- let href = this.buildLocation(redirect.options).url
2233
+ const location = this.buildLocation(redirect.options)
2234
+ let href = location.url
2234
2235
  if (this.origin && href.startsWith(this.origin)) {
2235
2236
  href = href.replace(this.origin, '') || '/'
2236
2237
  }
2237
- redirect.options.href = href
2238
- redirect.headers.set('Location', redirect.options.href)
2238
+ redirect.options.href = location.href
2239
+ redirect.headers.set('Location', href)
2239
2240
  }
2240
-
2241
2241
  if (!redirect.headers.get('Location')) {
2242
2242
  redirect.headers.set('Location', redirect.options.href)
2243
2243
  }
2244
-
2245
2244
  return redirect
2246
2245
  }
2247
2246