@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.
@@ -19,13 +19,18 @@ function composeRewrites(rewrites) {
19
19
  }
20
20
  function rewriteBasepath(opts) {
21
21
  const trimmedBasepath = path.trimPath(opts.basepath);
22
- const regex = new RegExp(
23
- `^/${trimmedBasepath}/`,
24
- opts.caseSensitive ? "" : "i"
25
- );
22
+ const normalizedBasepath = `/${trimmedBasepath}`;
23
+ const normalizedBasepathWithSlash = `${normalizedBasepath}/`;
24
+ const checkBasepath = opts.caseSensitive ? normalizedBasepath : normalizedBasepath.toLowerCase();
25
+ const checkBasepathWithSlash = opts.caseSensitive ? normalizedBasepathWithSlash : normalizedBasepathWithSlash.toLowerCase();
26
26
  return {
27
27
  input: ({ url }) => {
28
- url.pathname = url.pathname.replace(regex, "/");
28
+ const pathname = opts.caseSensitive ? url.pathname : url.pathname.toLowerCase();
29
+ if (pathname === checkBasepath) {
30
+ url.pathname = "/";
31
+ } else if (pathname.startsWith(checkBasepathWithSlash)) {
32
+ url.pathname = url.pathname.slice(normalizedBasepath.length);
33
+ }
29
34
  return url;
30
35
  },
31
36
  output: ({ url }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"rewrite.cjs","sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const regex = new RegExp(\n `^/${trimmedBasepath}/`,\n opts.caseSensitive ? '' : 'i',\n )\n return {\n input: ({ url }) => {\n url.pathname = url.pathname.replace(regex, '/')\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"names":["trimPath","joinPaths"],"mappings":";;;AAGO,SAAS,gBAAgB,UAAkC;AAChE,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,iBAAW,WAAW,UAAU;AAC9B,cAAM,oBAAoB,SAAS,GAAG;AAAA,MACxC;AACA,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,eAAS,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7C,cAAM,qBAAqB,SAAS,CAAC,GAAG,GAAG;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAEO,SAAS,gBAAgB,MAG7B;AACD,QAAM,kBAAkBA,KAAAA,SAAS,KAAK,QAAQ;AAC9C,QAAM,QAAQ,IAAI;AAAA,IAChB,KAAK,eAAe;AAAA,IACpB,KAAK,gBAAgB,KAAK;AAAA,EAAA;AAE5B,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,UAAI,WAAW,IAAI,SAAS,QAAQ,OAAO,GAAG;AAC9C,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,UAAI,WAAWC,eAAU,CAAC,KAAK,iBAAiB,IAAI,QAAQ,CAAC;AAC7D,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAEO,SAAS,oBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,QAAQ,EAAE,KAAK;AACpC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,qBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,SAAS,EAAE,KAAK;AACrC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;;;;;"}
1
+ {"version":3,"file":"rewrite.cjs","sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const normalizedBasepathWithSlash = `${normalizedBasepath}/`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = opts.caseSensitive\n ? normalizedBasepathWithSlash\n : normalizedBasepathWithSlash.toLowerCase()\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"names":["trimPath","joinPaths"],"mappings":";;;AAGO,SAAS,gBAAgB,UAAkC;AAChE,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,iBAAW,WAAW,UAAU;AAC9B,cAAM,oBAAoB,SAAS,GAAG;AAAA,MACxC;AACA,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,eAAS,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7C,cAAM,qBAAqB,SAAS,CAAC,GAAG,GAAG;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAEO,SAAS,gBAAgB,MAG7B;AACD,QAAM,kBAAkBA,KAAAA,SAAS,KAAK,QAAQ;AAC9C,QAAM,qBAAqB,IAAI,eAAe;AAC9C,QAAM,8BAA8B,GAAG,kBAAkB;AACzD,QAAM,gBAAgB,KAAK,gBACvB,qBACA,mBAAmB,YAAA;AACvB,QAAM,yBAAyB,KAAK,gBAChC,8BACA,4BAA4B,YAAA;AAEhC,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,YAAM,WAAW,KAAK,gBAClB,IAAI,WACJ,IAAI,SAAS,YAAA;AAGjB,UAAI,aAAa,eAAe;AAC9B,YAAI,WAAW;AAAA,MACjB,WAAW,SAAS,WAAW,sBAAsB,GAAG;AAEtD,YAAI,WAAW,IAAI,SAAS,MAAM,mBAAmB,MAAM;AAAA,MAC7D;AACA,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,UAAI,WAAWC,eAAU,CAAC,KAAK,iBAAiB,IAAI,QAAQ,CAAC;AAC7D,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAEO,SAAS,oBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,QAAQ,EAAE,KAAK;AACpC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,qBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,SAAS,EAAE,KAAK;AACrC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;;;;;"}
@@ -736,12 +736,13 @@ class RouterCore {
736
736
  };
737
737
  this.resolveRedirect = (redirect2) => {
738
738
  if (!redirect2.options.href) {
739
- let href = this.buildLocation(redirect2.options).url;
739
+ const location = this.buildLocation(redirect2.options);
740
+ let href = location.url;
740
741
  if (this.origin && href.startsWith(this.origin)) {
741
742
  href = href.replace(this.origin, "") || "/";
742
743
  }
743
- redirect2.options.href = href;
744
- redirect2.headers.set("Location", redirect2.options.href);
744
+ redirect2.options.href = location.href;
745
+ redirect2.headers.set("Location", href);
745
746
  }
746
747
  if (!redirect2.headers.get("Location")) {
747
748
  redirect2.headers.set("Location", redirect2.options.href);