@tanstack/router-core 1.141.1 → 1.141.2

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.
@@ -37,14 +37,14 @@ export interface ParsedLocation<TSearchObj extends AnySchema = {}> {
37
37
  unmaskOnReload?: boolean;
38
38
  /**
39
39
  * @private
40
- * @description The public href of the location, including the origin before any rewrites.
40
+ * @description The public href of the location.
41
41
  * If a rewrite is applied, the `href` property will be the rewritten URL.
42
42
  */
43
43
  publicHref: string;
44
44
  /**
45
45
  * @private
46
- * @description The full URL of the location, including the origin.
46
+ * @description The full URL of the location.
47
47
  * @private
48
48
  */
49
- url: string;
49
+ url: URL;
50
50
  }
@@ -208,15 +208,14 @@ class RouterCore {
208
208
  const searchStr = this.options.stringifySearch(parsedSearch);
209
209
  url.search = searchStr;
210
210
  const fullPath = url.href.replace(url.origin, "");
211
- const { pathname, hash } = url;
212
211
  return {
213
212
  href: fullPath,
214
213
  publicHref: href,
215
- url: url.href,
216
- pathname: utils.decodePath(pathname),
214
+ url,
215
+ pathname: utils.decodePath(url.pathname),
217
216
  searchStr,
218
217
  search: utils.replaceEqualDeep(previousLocation?.search, parsedSearch),
219
- hash: hash.split("#").reverse()[0] ?? "",
218
+ hash: url.hash.split("#").reverse()[0] ?? "",
220
219
  state: utils.replaceEqualDeep(previousLocation?.state, state)
221
220
  };
222
221
  };
@@ -377,7 +376,7 @@ class RouterCore {
377
376
  return {
378
377
  publicHref: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash,
379
378
  href: fullPath,
380
- url: rewrittenUrl.href,
379
+ url: rewrittenUrl,
381
380
  pathname: nextPathname,
382
381
  search: nextSearch,
383
382
  searchStr,
@@ -456,7 +455,16 @@ class RouterCore {
456
455
  if (isSameUrl && isSameState()) {
457
456
  this.load();
458
457
  } else {
459
- let { maskedLocation, hashScrollIntoView, ...nextHistory } = next;
458
+ let {
459
+ // eslint-disable-next-line prefer-const
460
+ maskedLocation,
461
+ // eslint-disable-next-line prefer-const
462
+ hashScrollIntoView,
463
+ // don't pass url into history since it is a URL instance that cannot be serialized
464
+ // eslint-disable-next-line prefer-const
465
+ url: _url,
466
+ ...nextHistory
467
+ } = next;
460
468
  if (maskedLocation) {
461
469
  nextHistory = {
462
470
  ...maskedLocation,
@@ -544,7 +552,7 @@ class RouterCore {
544
552
  if (reloadDocument) {
545
553
  if (!href) {
546
554
  const location = this.buildLocation({ to, ...rest });
547
- href = location.url;
555
+ href = location.url.href;
548
556
  }
549
557
  if (!rest.ignoreBlocker) {
550
558
  const historyWithBlockers = this.history;
@@ -589,18 +597,8 @@ class RouterCore {
589
597
  state: true,
590
598
  _includeValidateSearch: true
591
599
  });
592
- const normalizeUrl = (url) => {
593
- try {
594
- return encodeURI(decodeURI(url));
595
- } catch {
596
- return url;
597
- }
598
- };
599
- if (path.trimPath(normalizeUrl(this.latestLocation.href)) !== path.trimPath(normalizeUrl(nextLocation.href))) {
600
- let href = nextLocation.url;
601
- if (this.origin && href.startsWith(this.origin)) {
602
- href = href.replace(this.origin, "") || "/";
603
- }
600
+ if (this.latestLocation.publicHref !== nextLocation.publicHref || nextLocation.url.origin !== this.origin) {
601
+ const href = this.getParsedLocationHref(nextLocation);
604
602
  throw redirect.redirect({ href });
605
603
  }
606
604
  }
@@ -819,13 +817,17 @@ class RouterCore {
819
817
  this.shouldViewTransition = false;
820
818
  return this.load({ sync: opts?.sync });
821
819
  };
820
+ this.getParsedLocationHref = (location) => {
821
+ let href = location.url.href;
822
+ if (this.origin && location.url.origin === this.origin) {
823
+ href = href.replace(this.origin, "") || "/";
824
+ }
825
+ return href;
826
+ };
822
827
  this.resolveRedirect = (redirect2) => {
823
828
  if (!redirect2.options.href) {
824
829
  const location = this.buildLocation(redirect2.options);
825
- let href = location.url;
826
- if (this.origin && href.startsWith(this.origin)) {
827
- href = href.replace(this.origin, "") || "/";
828
- }
830
+ const href = this.getParsedLocationHref(location);
829
831
  redirect2.options.href = location.href;
830
832
  redirect2.headers.set("Location", href);
831
833
  }