@tanstack/react-router 1.94.1 → 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 @@
1
+ export declare function useCanGoBack(): boolean;
@@ -0,0 +1,8 @@
1
+ import { useRouterState } from "./useRouterState.js";
2
+ function useCanGoBack() {
3
+ return useRouterState({ select: (s) => s.location.state.__TSR_index !== 0 });
4
+ }
5
+ export {
6
+ useCanGoBack
7
+ };
8
+ //# sourceMappingURL=useCanGoBack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCanGoBack.js","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":[],"mappings":";AAEO,SAAS,eAAe;AACtB,SAAA,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,gBAAgB,GAAG;AAC7E;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.94.1",
3
+ "version": "1.95.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -53,7 +53,7 @@
53
53
  "jsesc": "^3.0.2",
54
54
  "tiny-invariant": "^1.3.3",
55
55
  "tiny-warning": "^1.0.3",
56
- "@tanstack/history": "1.90.0"
56
+ "@tanstack/history": "1.95.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@testing-library/jest-dom": "^6.6.3",
package/src/index.tsx CHANGED
@@ -317,6 +317,8 @@ export { useRouterState } from './useRouterState'
317
317
 
318
318
  export { useLocation } from './useLocation'
319
319
 
320
+ export { useCanGoBack } from './useCanGoBack'
321
+
320
322
  export {
321
323
  escapeJSON, // SSR
322
324
  useLayoutEffect, // SSR
package/src/router.ts CHANGED
@@ -1893,7 +1893,10 @@ export class Router<
1893
1893
  ...rest
1894
1894
  }: BuildNextOptions & CommitLocationOptions = {}) => {
1895
1895
  if (href) {
1896
- const parsed = parseHref(href, {})
1896
+ const currentIndex = this.history.location.state.__TSR_index
1897
+ const parsed = parseHref(href, {
1898
+ __TSR_index: replace ? currentIndex : currentIndex + 1,
1899
+ })
1897
1900
  rest.to = parsed.pathname
1898
1901
  rest.search = this.options.parseSearch(parsed.search)
1899
1902
  // remove the leading `#` from the hash
@@ -0,0 +1,5 @@
1
+ import { useRouterState } from './useRouterState'
2
+
3
+ export function useCanGoBack() {
4
+ return useRouterState({ select: (s) => s.location.state.__TSR_index !== 0 })
5
+ }