@tanstack/router-core 1.147.1 → 1.150.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.
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/redirect.d.cts +13 -0
- package/dist/cjs/route.cjs +3 -0
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +25 -0
- package/dist/cjs/utils.cjs +3 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/redirect.d.ts +13 -0
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.d.ts +25 -0
- package/dist/esm/route.js +3 -0
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +3 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/redirect.ts +29 -0
- package/src/route.ts +31 -0
- package/src/utils.ts +4 -2
package/src/route.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import invariant from 'tiny-invariant'
|
|
2
2
|
import { joinPaths, trimPathLeft } from './path'
|
|
3
3
|
import { notFound } from './not-found'
|
|
4
|
+
import { redirect } from './redirect'
|
|
4
5
|
import { rootRouteId } from './root'
|
|
5
6
|
import type { LazyRoute } from './fileRoute'
|
|
6
7
|
import type { NotFoundError } from './not-found'
|
|
8
|
+
import type { RedirectFnRoute } from './redirect'
|
|
7
9
|
import type { NavigateOptions, ParsePathParams } from './link'
|
|
8
10
|
import type { ParsedLocation } from './location'
|
|
9
11
|
import type {
|
|
@@ -773,6 +775,14 @@ export interface Route<
|
|
|
773
775
|
TServerMiddlewares,
|
|
774
776
|
THandlers
|
|
775
777
|
>
|
|
778
|
+
/**
|
|
779
|
+
* Create a redirect with `from` automatically set to this route's path.
|
|
780
|
+
* Enables relative redirects like `Route.redirect({ to: './overview' })`.
|
|
781
|
+
* @param opts Redirect options (same as `redirect()` but without `from`)
|
|
782
|
+
* @returns A redirect Response that can be thrown from loaders/beforeLoad
|
|
783
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction
|
|
784
|
+
*/
|
|
785
|
+
redirect: RedirectFnRoute<TFullPath>
|
|
776
786
|
}
|
|
777
787
|
|
|
778
788
|
export type AnyRoute = Route<
|
|
@@ -1903,6 +1913,16 @@ export class BaseRoute<
|
|
|
1903
1913
|
this.lazyFn = lazyFn
|
|
1904
1914
|
return this
|
|
1905
1915
|
}
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Create a redirect with `from` automatically set to this route's fullPath.
|
|
1919
|
+
* Enables relative redirects like `Route.redirect({ to: './overview' })`.
|
|
1920
|
+
* @param opts Redirect options (same as `redirect()` but without `from`)
|
|
1921
|
+
* @returns A redirect Response that can be thrown from loaders/beforeLoad
|
|
1922
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction
|
|
1923
|
+
*/
|
|
1924
|
+
redirect: RedirectFnRoute<TFullPath> = (opts) =>
|
|
1925
|
+
redirect({ from: this.fullPath, ...opts } as any)
|
|
1906
1926
|
}
|
|
1907
1927
|
|
|
1908
1928
|
export class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
@@ -1915,6 +1935,17 @@ export class BaseRouteApi<TId, TRouter extends AnyRouter = RegisteredRouter> {
|
|
|
1915
1935
|
notFound = (opts?: NotFoundError) => {
|
|
1916
1936
|
return notFound({ routeId: this.id as string, ...opts })
|
|
1917
1937
|
}
|
|
1938
|
+
|
|
1939
|
+
/**
|
|
1940
|
+
* Create a redirect with `from` automatically set to this route's path.
|
|
1941
|
+
* Enables relative redirects like `routeApi.redirect({ to: './overview' })`.
|
|
1942
|
+
* @param opts Redirect options (same as `redirect()` but without `from`)
|
|
1943
|
+
* @returns A redirect Response that can be thrown from loaders/beforeLoad
|
|
1944
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction
|
|
1945
|
+
*/
|
|
1946
|
+
redirect: RedirectFnRoute<RouteTypesById<TRouter, TId>['fullPath']> = (
|
|
1947
|
+
opts,
|
|
1948
|
+
) => redirect({ from: this.id as string, ...opts } as any)
|
|
1918
1949
|
}
|
|
1919
1950
|
|
|
1920
1951
|
export interface RootRoute<
|
package/src/utils.ts
CHANGED
|
@@ -219,11 +219,13 @@ const hasOwn = Object.prototype.hasOwnProperty
|
|
|
219
219
|
* This can be used for structural sharing between immutable JSON values for example.
|
|
220
220
|
* Do not use this with signals
|
|
221
221
|
*/
|
|
222
|
-
export function replaceEqualDeep<T>(prev: any, _next: T): T {
|
|
222
|
+
export function replaceEqualDeep<T>(prev: any, _next: T, _depth = 0): T {
|
|
223
223
|
if (prev === _next) {
|
|
224
224
|
return prev
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
if (_depth > 500) return _next
|
|
228
|
+
|
|
227
229
|
const next = _next as any
|
|
228
230
|
|
|
229
231
|
const array = isPlainArray(prev) && isPlainArray(next)
|
|
@@ -261,7 +263,7 @@ export function replaceEqualDeep<T>(prev: any, _next: T): T {
|
|
|
261
263
|
continue
|
|
262
264
|
}
|
|
263
265
|
|
|
264
|
-
const v = replaceEqualDeep(p, n)
|
|
266
|
+
const v = replaceEqualDeep(p, n, _depth + 1)
|
|
265
267
|
copy[key] = v
|
|
266
268
|
if (v === p) equalItems++
|
|
267
269
|
}
|