@tanstack/react-router 1.81.9 → 1.81.13

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/react-router",
3
- "version": "1.81.9",
3
+ "version": "1.81.13",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/link.tsx CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  useLayoutEffect,
13
13
  } from './utils'
14
14
  import { exactPathTest, removeTrailingSlash } from './path'
15
+ import { useMatch } from './useMatch'
15
16
  import type { ParsedLocation } from './location'
16
17
  import type { HistoryState } from '@tanstack/history'
17
18
  import type {
@@ -650,6 +651,16 @@ export function useLinkProps<
650
651
  structuralSharing: true as any,
651
652
  })
652
653
 
654
+ // In the rare event that the user bypasses type-safety and doesn't supply a `from`
655
+ // we'll use the current route as the `from` location so relative routing works as expected
656
+ const parentRouteId = useMatch({ strict: false, select: (s) => s.pathname })
657
+
658
+ // Use it as the default `from` location
659
+ options = {
660
+ from: parentRouteId,
661
+ ...options,
662
+ }
663
+
653
664
  const next = React.useMemo(
654
665
  () => router.buildLocation(options as any),
655
666
  [router, options, currentSearch],
package/src/router.ts CHANGED
@@ -2941,6 +2941,16 @@ export class Router<
2941
2941
 
2942
2942
  this.injectedHtml.push(cb)
2943
2943
  }
2944
+ injectScript: (script: string) => void = (script) => {
2945
+ this.injectHtml(
2946
+ `<script class='tsr-once'>${script}${
2947
+ process.env.NODE_ENV === 'development'
2948
+ ? `; console.info(\`Injected From Server:
2949
+ ${script}\`)`
2950
+ : ''
2951
+ }; __TSR__.cleanScripts()</script>`,
2952
+ )
2953
+ }
2944
2954
  streamedKeys: Set<string> = new Set()
2945
2955
 
2946
2956
  getStreamedValue = <T>(key: string): T | undefined => {
@@ -2968,15 +2978,8 @@ export class Router<
2968
2978
  )
2969
2979
 
2970
2980
  this.streamedKeys.add(key)
2971
- const children = `__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`
2972
-
2973
- this.injectHtml(
2974
- `<script class='tsr-once'>${children}${
2975
- process.env.NODE_ENV === 'development'
2976
- ? `; console.info(\`Injected From Server:
2977
- ${children}\`)`
2978
- : ''
2979
- }; __TSR__.cleanScripts()</script>`,
2981
+ this.injectScript(
2982
+ `__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`,
2980
2983
  )
2981
2984
  }
2982
2985