@tanstack/react-router
Advanced tools
Comparing version
import { UseParamsRoute } from './useParams.js'; | ||
import { UseMatchRoute } from './useMatch.js'; | ||
import { UseSearchRoute } from './useSearch.js'; | ||
import { AnyContext, AnyRoute, AnyRouter, Constrain, ConstrainLiteral, FileBaseRouteOptions, FileRoutesByPath, LazyRouteOptions, RegisteredRouter, ResolveParams, Route, RouteById, RouteConstraints, RouteIds, RouteLoaderFn, UpdatableRouteOptions } from '@tanstack/router-core'; | ||
import { AnyContext, AnyRoute, AnyRouter, Constrain, ConstrainLiteral, FileBaseRouteOptions, FileRoutesByPath, LazyRouteOptions, RegisteredRouter, ResolveParams, Route, RouteById, RouteConstraints, RouteIds, RouteLoaderFn, UpdatableRouteOptions, UseNavigateResult } from '@tanstack/router-core'; | ||
import { UseLoaderDepsRoute } from './useLoaderDeps.js'; | ||
import { UseLoaderDataRoute } from './useLoaderData.js'; | ||
import { UseRouteContextRoute } from './useRouteContext.js'; | ||
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path: TFilePath): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute']; | ||
export declare function createFileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']>(path?: TFilePath): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute']; | ||
/** | ||
@@ -14,5 +14,5 @@ @deprecated It's no longer recommended to use the `FileRoute` class directly. | ||
export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']> { | ||
path: TFilePath; | ||
path?: TFilePath | undefined; | ||
silent?: boolean; | ||
constructor(path: TFilePath, _opts?: { | ||
constructor(path?: TFilePath | undefined, _opts?: { | ||
silent: boolean; | ||
@@ -28,2 +28,13 @@ }); | ||
export declare function FileRouteLoader<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(_path: TFilePath): <TLoaderFn>(loaderFn: Constrain<TLoaderFn, RouteLoaderFn<TRoute['parentRoute'], TRoute['types']['id'], TRoute['types']['params'], TRoute['types']['loaderDeps'], TRoute['types']['routerContext'], TRoute['types']['routeContextFn'], TRoute['types']['beforeLoadFn']>>) => TLoaderFn; | ||
declare module '@tanstack/router-core' { | ||
interface LazyRoute<in out TRoute extends AnyRoute> { | ||
useMatch: UseMatchRoute<TRoute['id']>; | ||
useRouteContext: UseRouteContextRoute<TRoute['id']>; | ||
useSearch: UseSearchRoute<TRoute['id']>; | ||
useParams: UseParamsRoute<TRoute['id']>; | ||
useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>; | ||
useLoaderData: UseLoaderDataRoute<TRoute['id']>; | ||
useNavigate: () => UseNavigateResult<TRoute['fullPath']>; | ||
} | ||
} | ||
export declare class LazyRoute<TRoute extends AnyRoute> { | ||
@@ -42,5 +53,5 @@ options: { | ||
useLoaderData: UseLoaderDataRoute<TRoute['id']>; | ||
useNavigate: () => import('@tanstack/router-core').UseNavigateResult<any>; | ||
useNavigate: () => UseNavigateResult<TRoute["fullPath"]>; | ||
} | ||
export declare function createLazyRoute<TRouter extends AnyRouter = RegisteredRouter, TId extends string = string, TRoute extends AnyRoute = RouteById<TRouter['routeTree'], TId>>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>): (opts: LazyRouteOptions) => LazyRoute<TRoute>; | ||
export declare function createLazyFileRoute<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute>; |
@@ -11,2 +11,7 @@ import warning from "tiny-warning"; | ||
function createFileRoute(path) { | ||
if (typeof path === "object") { | ||
return new FileRoute(path, { | ||
silent: true | ||
}).createRoute(path); | ||
} | ||
return new FileRoute(path, { | ||
@@ -90,2 +95,5 @@ silent: true | ||
function createLazyFileRoute(id) { | ||
if (typeof id === "object") { | ||
return new LazyRoute(id); | ||
} | ||
return (opts) => new LazyRoute({ id, ...opts }); | ||
@@ -92,0 +100,0 @@ } |
@@ -52,8 +52,25 @@ import * as React from "react"; | ||
const links = useRouterState({ | ||
select: (state) => state.matches.map((match) => match.links).filter(Boolean).flat(1).map((link) => ({ | ||
tag: "link", | ||
attrs: { | ||
...link | ||
} | ||
})), | ||
select: (state) => { | ||
var _a; | ||
const constructed = state.matches.map((match) => match.links).filter(Boolean).flat(1).map((link) => ({ | ||
tag: "link", | ||
attrs: { | ||
...link | ||
} | ||
})); | ||
const manifest = (_a = router.ssr) == null ? void 0 : _a.manifest; | ||
const assets = state.matches.map((match) => { | ||
var _a2; | ||
return ((_a2 = manifest == null ? void 0 : manifest.routes[match.routeId]) == null ? void 0 : _a2.assets) ?? []; | ||
}).filter(Boolean).flat(1).filter((asset) => asset.tag === "link").map( | ||
(asset) => ({ | ||
tag: "link", | ||
attrs: { | ||
...asset.attrs, | ||
suppressHydrationWarning: true | ||
} | ||
}) | ||
); | ||
return [...constructed, ...assets]; | ||
}, | ||
structuralSharing: true | ||
@@ -60,0 +77,0 @@ }); |
@@ -5,3 +5,3 @@ export { default as invariant } from 'tiny-invariant'; | ||
pick, functionalUpdate, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, shallow, createControlledPromise, retainSearchParams, stripSearchParams, } from '@tanstack/router-core'; | ||
export type { AnyRoute, StartSerializer, Serializable, SerializerParse, SerializerParseBy, SerializerStringify, SerializerStringifyBy, DeferredPromiseState, DeferredPromise, ParsedLocation, ParsePathParams, RemoveTrailingSlashes, RemoveLeadingSlashes, ActiveOptions, Segment, ResolveRelativePath, RootRouteId, AnyPathParams, ResolveParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, TrimPath, TrimPathLeft, TrimPathRight, ParseSplatParams, SplatParams, StringifyParamsFn, ParamsOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveLoaderData, ResolveRouteContext, SearchSerializer, SearchParser, TrailingSlashOption, ExtractedEntry, ExtractedStream, ExtractedPromise, StreamState, Manifest, RouterManagedTag, ControlledPromise, Constrain, Expand, MergeAll, Assign, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, Register, AnyValidator, DefaultValidator, ValidatorFn, AnySchema, AnyValidatorAdapter, AnyValidatorFn, AnyValidatorObj, ResolveValidatorInputFn, ResolveValidatorOutputFn, ResolveSearchValidatorInput, ResolveSearchValidatorInputFn, Validator, ValidatorAdapter, ValidatorObj, FileRoutesByPath, RouteById, RootRouteOptions, SerializerExtensions, } from '@tanstack/router-core'; | ||
export type { AnyRoute, StartSerializer, Serializable, SerializerParse, SerializerParseBy, SerializerStringify, SerializerStringifyBy, DeferredPromiseState, DeferredPromise, ParsedLocation, RemoveTrailingSlashes, RemoveLeadingSlashes, ActiveOptions, Segment, ResolveRelativePath, RootRouteId, AnyPathParams, ResolveParams, ResolveOptionalParams, ResolveRequiredParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, TrimPath, TrimPathLeft, TrimPathRight, StringifyParamsFn, ParamsOptions, InferAllParams, InferAllContext, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveLoaderData, ResolveRouteContext, SearchSerializer, SearchParser, TrailingSlashOption, ExtractedEntry, ExtractedStream, ExtractedPromise, StreamState, Manifest, RouterManagedTag, ControlledPromise, Constrain, Expand, MergeAll, Assign, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, Register, AnyValidator, DefaultValidator, ValidatorFn, AnySchema, AnyValidatorAdapter, AnyValidatorFn, AnyValidatorObj, ResolveValidatorInputFn, ResolveValidatorOutputFn, ResolveSearchValidatorInput, ResolveSearchValidatorInputFn, Validator, ValidatorAdapter, ValidatorObj, FileRoutesByPath, RouteById, RootRouteOptions, SerializerExtensions, CreateFileRoute, } from '@tanstack/router-core'; | ||
export type * from './serializer.js'; | ||
@@ -18,3 +18,3 @@ export { createHistory, createBrowserHistory, createHashHistory, createMemoryHistory, } from '@tanstack/history'; | ||
export { useLinkProps, createLink, Link, linkOptions } from './link.js'; | ||
export type { InferDescendantToPaths, RelativeToPath, RelativeToParentPath, RelativeToCurrentPath, AbsoluteToPath, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, LinkOptions, MakeOptionalPathParams, FileRouteTypes, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, ResolveAllParamsFromParent, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, RouteIds, NavigateFn, BuildLocationFn, FullSearchSchemaOption, MakeRemountDepsOptionsUnion, RemountDepsOptions, ResolveFullPath, AnyRouteWithContext, AnyRouterWithContext, CommitLocationOptions, MatchLocation, UseNavigateResult, AnyRedirect, Redirect, ResolvedRedirect, MakeRouteMatch, MakeRouteMatchUnion, RouteMatch, AnyRouteMatch, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, LazyRouteOptions, AnyRouter, RegisteredRouter, RouterContextOptions, ControllablePromise, InjectedHtmlEntry, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, RouteConstraints, RouteMask, MatchRouteOptions, } from '@tanstack/router-core'; | ||
export type { InferDescendantToPaths, RelativeToPath, RelativeToParentPath, RelativeToCurrentPath, AbsoluteToPath, RelativeToPathAutoComplete, NavigateOptions, ToOptions, ToMaskOptions, ToSubOptions, ResolveRoute, SearchParamOptions, PathParamOptions, ToPathOption, LinkOptions, MakeOptionalPathParams, FileRouteTypes, RouteContextParameter, BeforeLoadContextParameter, ResolveAllContext, ResolveAllParamsFromParent, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, RouteIds, NavigateFn, BuildLocationFn, FullSearchSchemaOption, MakeRemountDepsOptionsUnion, RemountDepsOptions, ResolveFullPath, AnyRouteWithContext, AnyRouterWithContext, CommitLocationOptions, MatchLocation, UseNavigateResult, AnyRedirect, Redirect, ResolvedRedirect, MakeRouteMatch, MakeRouteMatchUnion, RouteMatch, AnyRouteMatch, RouteContextFn, RouteContextOptions, BeforeLoadFn, BeforeLoadContextOptions, ContextOptions, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, LazyRouteOptions, AnyRouter, RegisteredRouter, RouterContextOptions, ControllablePromise, InjectedHtmlEntry, RouterOptions, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, RouteConstraints, RouteMask, MatchRouteOptions, CreateLazyFileRoute, } from '@tanstack/router-core'; | ||
export type { UseLinkPropsOptions, ActiveLinkOptions, LinkProps, LinkComponent, LinkComponentProps, CreateLinkProps, } from './link.js'; | ||
@@ -21,0 +21,0 @@ export { Matches, useMatchRoute, MatchRoute, useMatches, useParentMatches, useChildMatches, } from './Matches.js'; |
@@ -8,2 +8,3 @@ import { jsx } from "react/jsx-runtime"; | ||
import { useForwardedRef, useIntersectionObserver, useLayoutEffect } from "./utils.js"; | ||
import { useMatch } from "./useMatch.js"; | ||
import { useMatches } from "./Matches.js"; | ||
@@ -64,8 +65,11 @@ function useLinkProps(options, forwardedRef) { | ||
}); | ||
const from = useMatches({ | ||
select: (matches) => { | ||
var _a; | ||
return options.from ?? ((_a = matches[matches.length - 1]) == null ? void 0 : _a.fullPath); | ||
} | ||
const isRelativeFromPath = options.relative === "path"; | ||
const nearestFrom = useMatch({ | ||
strict: false, | ||
select: (match) => isRelativeFromPath ? void 0 : match.fullPath | ||
}); | ||
const leafFrom = useMatches({ | ||
select: (matches) => isRelativeFromPath ? matches[matches.length - 1].fullPath : void 0 | ||
}); | ||
const from = options.from ?? (isRelativeFromPath ? leafFrom : nearestFrom); | ||
const _options = React.useMemo(() => ({ ...options, from }), [options, from]); | ||
@@ -72,0 +76,0 @@ const next = React.useMemo( |
@@ -217,2 +217,5 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime"; | ||
}); | ||
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null; | ||
if (router.isShell) | ||
return /* @__PURE__ */ jsx(React.Suspense, { fallback: pendingElement, children: /* @__PURE__ */ jsx(ShellInner, {}) }); | ||
if (parentGlobalNotFound) { | ||
@@ -225,3 +228,2 @@ return renderRouteNotFound(router, route, void 0); | ||
const nextMatch = /* @__PURE__ */ jsx(Match, { matchId: childMatchId }); | ||
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null; | ||
if (matchId === rootRouteId) { | ||
@@ -232,2 +234,5 @@ return /* @__PURE__ */ jsx(React.Suspense, { fallback: pendingElement, children: nextMatch }); | ||
}); | ||
function ShellInner() { | ||
throw new Error("ShellBoundaryError"); | ||
} | ||
export { | ||
@@ -234,0 +239,0 @@ Match, |
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js'; | ||
import { ReactNode } from './route.js'; | ||
import { AnyRouter, DeepPartial, MakeOptionalPathParams, MakeOptionalSearchParams, MakeRouteMatchUnion, MaskOptions, MatchRouteOptions, NoInfer, RegisteredRouter, ResolveRelativePath, ResolveRoute, RouteByPath, ToSubOptionsProps } from '@tanstack/router-core'; | ||
import { AnyRouter, DeepPartial, Expand, MakeOptionalPathParams, MakeOptionalSearchParams, MakeRouteMatchUnion, MaskOptions, MatchRouteOptions, NoInfer, RegisteredRouter, ResolveRelativePath, ResolveRoute, RouteByPath, ToSubOptionsProps } from '@tanstack/router-core'; | ||
import * as React from 'react'; | ||
@@ -15,3 +15,3 @@ declare module '@tanstack/router-core' { | ||
export type UseMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = ToSubOptionsProps<TRouter, TFrom, TTo> & DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> & DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> & MaskOptions<TRouter, TMaskFrom, TMaskTo> & MatchRouteOptions; | ||
export declare function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => false | ResolveRoute<TRouter, TFrom, TTo>["types"]["allParams"]; | ||
export declare function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => false | Expand<ResolveRoute<TRouter, TFrom, TTo>["types"]["allParams"]>; | ||
export type MakeMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & { | ||
@@ -18,0 +18,0 @@ children?: ((params?: RouteByPath<TRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode; |
import { RouterCore } from "@tanstack/router-core"; | ||
import { createFileRoute, createLazyFileRoute } from "./fileRoute.js"; | ||
const createRouter = (options) => { | ||
@@ -10,2 +11,9 @@ return new Router(options); | ||
} | ||
if (typeof globalThis !== "undefined") { | ||
globalThis.createFileRoute = createFileRoute; | ||
globalThis.createLazyFileRoute = createLazyFileRoute; | ||
} else if (typeof window !== "undefined") { | ||
window.createFileRoute = createFileRoute; | ||
window.createFileRoute = createLazyFileRoute; | ||
} | ||
export { | ||
@@ -12,0 +20,0 @@ Router, |
@@ -9,10 +9,12 @@ import { jsx } from "react/jsx-runtime"; | ||
}) { | ||
router.update({ | ||
...router.options, | ||
...rest, | ||
context: { | ||
...router.options.context, | ||
...rest.context | ||
} | ||
}); | ||
if (Object.keys(rest).length > 0) { | ||
router.update({ | ||
...router.options, | ||
...rest, | ||
context: { | ||
...router.options.context, | ||
...rest.context | ||
} | ||
}); | ||
} | ||
const routerContext = getRouterContext(); | ||
@@ -19,0 +21,0 @@ const provider = /* @__PURE__ */ jsx(routerContext.Provider, { value: router, children }); |
@@ -42,3 +42,4 @@ import { jsx, Fragment } from "react/jsx-runtime"; | ||
})) | ||
}) | ||
}), | ||
structuralSharing: true | ||
}); | ||
@@ -45,0 +46,0 @@ const allScripts = [...scripts, ...assetScripts]; |
@@ -60,3 +60,6 @@ import * as React from "react"; | ||
const parsedLocation = router.parseLocation(void 0, location); | ||
const matchedRoutes = router.getMatchedRoutes(parsedLocation); | ||
const matchedRoutes = router.getMatchedRoutes( | ||
parsedLocation.pathname, | ||
void 0 | ||
); | ||
if (matchedRoutes.foundRoute === void 0) { | ||
@@ -63,0 +66,0 @@ throw new Error(`No route found for location ${location.href}`); |
import * as React from "react"; | ||
import { useRouter } from "./useRouter.js"; | ||
import { useMatch } from "./useMatch.js"; | ||
function useNavigate(_defaultOpts) { | ||
const { navigate } = useRouter(); | ||
const { navigate, state } = useRouter(); | ||
const matchIndex = useMatch({ | ||
strict: false, | ||
select: (match) => match.index | ||
}); | ||
return React.useCallback( | ||
(options) => { | ||
const isRelativeFromPath = options.relative === "path"; | ||
const from = options.from ?? (_defaultOpts == null ? void 0 : _defaultOpts.from) ?? (isRelativeFromPath ? state.matches[state.matches.length - 1].fullPath : state.matches[matchIndex].fullPath); | ||
return navigate({ | ||
from: _defaultOpts == null ? void 0 : _defaultOpts.from, | ||
...options | ||
...options, | ||
from | ||
}); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[_defaultOpts == null ? void 0 : _defaultOpts.from, navigate] | ||
@@ -17,11 +25,10 @@ ); | ||
const router = useRouter(); | ||
const navigate = useNavigate(); | ||
const previousPropsRef = React.useRef(null); | ||
React.useEffect(() => { | ||
if (previousPropsRef.current !== props) { | ||
router.navigate({ | ||
...props | ||
}); | ||
navigate(props); | ||
previousPropsRef.current = props; | ||
} | ||
}, [router, props]); | ||
}, [router, props, navigate]); | ||
return null; | ||
@@ -28,0 +35,0 @@ } |
{ | ||
"name": "@tanstack/react-router", | ||
"version": "1.120.5", | ||
"version": "1.121.0-alpha.1", | ||
"description": "Modern and scalable routing for React applications", | ||
@@ -56,4 +56,4 @@ "author": "Tanner Linsley", | ||
"tiny-warning": "^1.0.3", | ||
"@tanstack/history": "1.115.0", | ||
"@tanstack/router-core": "1.120.5" | ||
"@tanstack/history": "1.121.0-alpha.1", | ||
"@tanstack/router-core": "1.121.0-alpha.1" | ||
}, | ||
@@ -60,0 +60,0 @@ "devDependencies": { |
@@ -31,2 +31,3 @@ import warning from 'tiny-warning' | ||
UpdatableRouteOptions, | ||
UseNavigateResult, | ||
} from '@tanstack/router-core' | ||
@@ -45,4 +46,9 @@ import type { UseLoaderDepsRoute } from './useLoaderDeps' | ||
>( | ||
path: TFilePath, | ||
path?: TFilePath, | ||
): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] { | ||
if (typeof path === 'object') { | ||
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, { | ||
silent: true, | ||
}).createRoute(path) as any | ||
} | ||
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, { | ||
@@ -68,3 +74,3 @@ silent: true, | ||
constructor( | ||
public path: TFilePath, | ||
public path?: TFilePath, | ||
_opts?: { silent: boolean }, | ||
@@ -165,2 +171,14 @@ ) { | ||
declare module '@tanstack/router-core' { | ||
export interface LazyRoute<in out TRoute extends AnyRoute> { | ||
useMatch: UseMatchRoute<TRoute['id']> | ||
useRouteContext: UseRouteContextRoute<TRoute['id']> | ||
useSearch: UseSearchRoute<TRoute['id']> | ||
useParams: UseParamsRoute<TRoute['id']> | ||
useLoaderDeps: UseLoaderDepsRoute<TRoute['id']> | ||
useLoaderData: UseLoaderDataRoute<TRoute['id']> | ||
useNavigate: () => UseNavigateResult<TRoute['fullPath']> | ||
} | ||
} | ||
export class LazyRoute<TRoute extends AnyRoute> { | ||
@@ -221,3 +239,3 @@ options: { | ||
useNavigate = () => { | ||
useNavigate = (): UseNavigateResult<TRoute['fullPath']> => { | ||
const router = useRouter() | ||
@@ -244,4 +262,8 @@ return useNavigate({ from: router.routesById[this.options.id].fullPath }) | ||
TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'], | ||
>(id: TFilePath) { | ||
>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute> { | ||
if (typeof id === 'object') { | ||
return new LazyRoute<TRoute>(id) as any | ||
} | ||
return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts }) | ||
} |
import { RouterCore } from '@tanstack/router-core' | ||
import { createFileRoute, createLazyFileRoute } from './fileRoute' | ||
import type { RouterHistory } from '@tanstack/history' | ||
@@ -108,1 +109,9 @@ import type { | ||
} | ||
if (typeof globalThis !== 'undefined') { | ||
;(globalThis as any).createFileRoute = createFileRoute | ||
;(globalThis as any).createLazyFileRoute = createLazyFileRoute | ||
} else if (typeof window !== 'undefined') { | ||
;(window as any).createFileRoute = createFileRoute | ||
;(window as any).createFileRoute = createLazyFileRoute | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
754787
2.52%10129
2.16%1
Infinity%+ Added
+ Added
- Removed
- Removed