@tanstack/react-router 1.94.0 → 1.95.0

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.
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useRouterState = require("./useRouterState.cjs");
4
+ function useCanGoBack() {
5
+ return useRouterState.useRouterState({ select: (s) => s.location.state.__TSR_index !== 0 });
6
+ }
7
+ exports.useCanGoBack = useCanGoBack;
8
+ //# sourceMappingURL=useCanGoBack.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCanGoBack.cjs","sources":["../../src/useCanGoBack.ts"],"sourcesContent":["import { useRouterState } from './useRouterState'\n\nexport function useCanGoBack() {\n return useRouterState({ select: (s) => s.location.state.__TSR_index !== 0 })\n}\n"],"names":["useRouterState"],"mappings":";;;AAEO,SAAS,eAAe;AACtB,SAAAA,eAAA,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,gBAAgB,GAAG;AAC7E;;"}
@@ -0,0 +1 @@
1
+ export declare function useCanGoBack(): boolean;
@@ -54,6 +54,7 @@ export { useRouteContext } from './useRouteContext.js';
54
54
  export { useRouter } from './useRouter.js';
55
55
  export { useRouterState } from './useRouterState.js';
56
56
  export { useLocation } from './useLocation.js';
57
+ export { useCanGoBack } from './useCanGoBack.js';
57
58
  export { escapeJSON, // SSR
58
59
  useLayoutEffect, // SSR
59
60
  pick, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, useStableCallback, shallow, } from './utils.js';
package/dist/esm/index.js CHANGED
@@ -34,6 +34,7 @@ import { useRouteContext } from "./useRouteContext.js";
34
34
  import { useRouter } from "./useRouter.js";
35
35
  import { useRouterState } from "./useRouterState.js";
36
36
  import { useLocation } from "./useLocation.js";
37
+ import { useCanGoBack } from "./useCanGoBack.js";
37
38
  import { createControlledPromise, deepEqual, escapeJSON, functionalUpdate, isPlainArray, isPlainObject, pick, replaceEqualDeep, shallow, useLayoutEffect, useStableCallback } from "./utils.js";
38
39
  import { CatchNotFound, DefaultGlobalNotFound, isNotFound, notFound } from "./not-found.js";
39
40
  import { retainSearchParams, stripSearchParams } from "./searchMiddleware.js";
@@ -129,6 +130,7 @@ export {
129
130
  trimPathRight,
130
131
  useAwaited,
131
132
  useBlocker,
133
+ useCanGoBack,
132
134
  useChildMatches,
133
135
  useElementScrollRestoration,
134
136
  useLayoutEffect,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -578,7 +578,10 @@ class Router {
578
578
  ...rest
579
579
  } = {}) => {
580
580
  if (href) {
581
- const parsed = parseHref(href, {});
581
+ const currentIndex = this.history.location.state.__TSR_index;
582
+ const parsed = parseHref(href, {
583
+ __TSR_index: replace ? currentIndex : currentIndex + 1
584
+ });
582
585
  rest.to = parsed.pathname;
583
586
  rest.search = this.options.parseSearch(parsed.search);
584
587
  rest.hash = parsed.hash.slice(1);
@@ -1007,6 +1010,10 @@ class Router {
1007
1010
  let loaderIsRunningAsync = false;
1008
1011
  if (prevLoaderPromise) {
1009
1012
  await prevLoaderPromise;
1013
+ const match = this.getMatch(matchId);
1014
+ if (match.error) {
1015
+ handleRedirectAndNotFound(match, match.error);
1016
+ }
1010
1017
  } else {
1011
1018
  const parentMatchPromise = matchPromises[index - 1];
1012
1019
  const route = this.looseRoutesById[routeId];