@tanstack/react-router 1.3.5 → 1.4.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/build/cjs/CatchBoundary.js.map +1 -1
- package/build/cjs/RouterProvider.js +6 -4
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/esm/index.js +6 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +353 -353
- package/build/types/CatchBoundary.d.ts +1 -1
- package/build/types/RouterProvider.d.ts +5 -2
- package/build/umd/index.development.js +6 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/CatchBoundary.tsx +1 -1
- package/src/RouterProvider.tsx +12 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CatchBoundary.js","sources":["../../src/CatchBoundary.tsx"],"sourcesContent":["import * as React from 'react'\n\nexport function CatchBoundary(props: {\n getResetKey: () => string\n children: any\n errorComponent?: any\n onCatch
|
|
1
|
+
{"version":3,"file":"CatchBoundary.js","sources":["../../src/CatchBoundary.tsx"],"sourcesContent":["import * as React from 'react'\n\nexport function CatchBoundary(props: {\n getResetKey: () => string\n children: any\n errorComponent?: any\n onCatch?: (error: any) => void\n}) {\n const errorComponent = props.errorComponent ?? ErrorComponent\n\n return (\n <CatchBoundaryImpl\n getResetKey={props.getResetKey}\n onCatch={props.onCatch}\n children={({ error }) => {\n if (error) {\n return React.createElement(errorComponent, {\n error,\n })\n }\n\n return props.children\n }}\n />\n )\n}\n\nexport class CatchBoundaryImpl extends React.Component<{\n getResetKey: () => string\n children: (props: { error: any; reset: () => void }) => any\n onCatch?: (error: any) => void\n}> {\n state = { error: null } as any\n static getDerivedStateFromProps(props: any) {\n return { resetKey: props.getResetKey() }\n }\n static getDerivedStateFromError(error: any) {\n return { error }\n }\n componentDidUpdate(\n prevProps: Readonly<{\n getResetKey: () => string\n children: (props: { error: any; reset: () => void }) => any\n onCatch?: ((error: any, info: any) => void) | undefined\n }>,\n prevState: any,\n ): void {\n if (prevState.error && prevState.resetKey !== this.state.resetKey) {\n this.setState({ error: null })\n }\n }\n componentDidCatch(error: any) {\n console.error(error)\n this.props.onCatch?.(error)\n }\n render() {\n return this.props.children(this.state)\n }\n}\n\nexport function ErrorComponent({ error }: { error: any }) {\n const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production')\n\n return (\n <div style={{ padding: '.5rem', maxWidth: '100%' }}>\n <div style={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>\n <strong style={{ fontSize: '1rem' }}>Something went wrong!</strong>\n <button\n style={{\n appearance: 'none',\n fontSize: '.6em',\n border: '1px solid currentColor',\n padding: '.1rem .2rem',\n fontWeight: 'bold',\n borderRadius: '.25rem',\n }}\n onClick={() => setShow((d) => !d)}\n >\n {show ? 'Hide Error' : 'Show Error'}\n </button>\n </div>\n <div style={{ height: '.25rem' }} />\n {show ? (\n <div>\n <pre\n style={{\n fontSize: '.7em',\n border: '1px solid red',\n borderRadius: '.25rem',\n padding: '.3rem',\n color: 'red',\n overflow: 'auto',\n }}\n >\n {error.message ? <code>{error.message}</code> : null}\n </pre>\n </div>\n ) : null}\n </div>\n )\n}\n"],"names":["CatchBoundary","props","errorComponent","ErrorComponent","React","createElement","CatchBoundaryImpl","getResetKey","onCatch","children","error","Component","state","getDerivedStateFromProps","resetKey","getDerivedStateFromError","componentDidUpdate","prevProps","prevState","setState","componentDidCatch","console","render","show","setShow","useState","process","env","NODE_ENV","style","padding","maxWidth","display","alignItems","gap","fontSize","appearance","border","fontWeight","borderRadius","onClick","d","height","color","overflow","message"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,SAASA,aAAaA,CAACC,KAK7B,EAAE;AACD,EAAA,MAAMC,cAAc,GAAGD,KAAK,CAACC,cAAc,IAAIC,cAAc,CAAA;AAE7D,EAAA,oBACEC,gBAAA,CAAAC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AAC,eACNnB,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AAAKwB,IAAAA,KAAK,EAAE;AAAEa,MAAAA,MAAM,EAAE,QAAA;AAAS,KAAA;GAAI,CAAC,EACnCnB,IAAI,gBACHnB,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA,IAAA,eACED,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AACEwB,IAAAA,KAAK,EAAE;AACLM,MAAAA,QAAQ,EAAE,MAAM;AAChBE,MAAAA,MAAM,EAAE,eAAe;AACvBE,MAAAA,YAAY,EAAE,QAAQ;AACtBT,MAAAA,OAAO,EAAE,OAAO;AAChBa,MAAAA,KAAK,EAAE,KAAK;AACZC,MAAAA,QAAQ,EAAE,MAAA;AACZ,KAAA;AAAE,GAAA,EAEDlC,KAAK,CAACmC,OAAO,gBAAGzC,gBAAA,CAAAC,aAAA,CAAOK,MAAAA,EAAAA,IAAAA,EAAAA,KAAK,CAACmC,OAAc,CAAC,GAAG,IAC7C,CACF,CAAC,GACJ,IACD,CAAC,CAAA;AAEV;;;;;;"}
|
|
@@ -158,13 +158,15 @@ function getRouteMatch(state, id) {
|
|
|
158
158
|
return [...state.cachedMatches, ...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
|
|
159
159
|
}
|
|
160
160
|
function useRouterState(opts) {
|
|
161
|
-
const
|
|
162
|
-
|
|
161
|
+
const contextRouter = useRouter({
|
|
162
|
+
warn: opts?.router === undefined
|
|
163
|
+
});
|
|
164
|
+
return reactStore.useStore((opts?.router || contextRouter).__store, opts?.select);
|
|
163
165
|
}
|
|
164
|
-
function useRouter() {
|
|
166
|
+
function useRouter(opts) {
|
|
165
167
|
const resolvedContext = typeof document !== 'undefined' ? window.__TSR_ROUTER_CONTEXT__ || exports.routerContext : exports.routerContext;
|
|
166
168
|
const value = React__namespace.useContext(resolvedContext);
|
|
167
|
-
warning(value, 'useRouter must be used inside a <RouterProvider> component!');
|
|
169
|
+
warning(opts?.warn && value, 'useRouter must be used inside a <RouterProvider> component!');
|
|
168
170
|
return value;
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { useStore } from '@tanstack/react-store'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ResolveRelativePath, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RouteById, RoutePaths } from './routeInfo'\nimport {\n BuildNextOptions,\n RegisteredRouter,\n Router,\n RouterOptions,\n RouterState,\n} from './router'\nimport { NoInfer, pick, useLayoutEffect } from './utils'\nimport { MatchRouteOptions } from './Matches'\nimport { RouteMatch } from './Matches'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type MatchRouteFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n>(\n location: ToOptions<TRouteTree, TFrom, TTo>,\n opts?: MatchRouteOptions,\n) => false | RouteById<TRouteTree, TResolved>['types']['allParams']\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = (\n opts: ToOptions<TRouteTree>,\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport let routerContext = React.createContext<Router<any>>(null!)\n\nif (typeof document !== 'undefined') {\n if (window.__TSR_ROUTER_CONTEXT__) {\n routerContext = window.__TSR_ROUTER_CONTEXT__\n } else {\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n }\n}\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const mountLoadCount = React.useRef(0)\n const router = useRouter()\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (routerState.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n const nextLocation = router.buildLocation({\n search: true,\n params: true,\n hash: true,\n state: true,\n })\n\n if (routerState.location.href !== nextLocation.href) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (!window.__TSR_DEHYDRATED__ && !mountLoadCount.current) {\n mountLoadCount.current++\n tryLoad()\n }\n }, [])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport function useRouterState<\n TSelected = RouterState<RegisteredRouter['routeTree']>,\n>(opts?: {\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const router = useRouter()\n return useStore(router.__store, opts?.select as any)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(): Router<TRouteTree> {\n const resolvedContext =\n typeof document !== 'undefined'\n ? window.__TSR_ROUTER_CONTEXT__ || routerContext\n : routerContext\n const value = React.useContext(resolvedContext)\n warning(value, 'useRouter must be used inside a <RouterProvider> component!')\n return value as any\n}\n"],"names":["useTransition","React","cb","routerContext","createContext","document","window","__TSR_ROUTER_CONTEXT__","RouterProvider","router","rest","update","options","context","matches","InnerWrap","createElement","Matches","provider","Provider","value","Transitioner","Wrap","mountLoadCount","useRef","useRouter","routerState","useRouterState","select","s","pick","isTransitioning","startReactTransition","useEffect","__store","setState","tryLoad","apply","load","err","console","error","useLayoutEffect","unsub","history","subscribe","latestLocation","parseLocation","location","nextLocation","buildLocation","search","params","hash","state","href","commitLocation","replace","isLoading","resolvedLocation","emit","type","fromLocation","toLocation","pathChanged","querySelector","el","getElementById","scrollIntoView","__TSR_DEHYDRATED__","current","getRouteMatch","id","cachedMatches","pendingMatches","find","d","opts","useStore","resolvedContext","useContext","warning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,aAAa,GACjBC,gBAAK,CAACD,aAAa,KAClB,MAAM,CACL,KAAK,EACJE,EAAE,IAAK;AACNA,EAAAA,EAAE,EAAE,CAAA;AACN,CAAC,CACF,CAAC,CAAA;AAuCOC,qBAAa,gBAAGF,gBAAK,CAACG,aAAa,CAAc,IAAK,EAAC;AAElE,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EACnC,IAAIC,MAAM,CAACC,sBAAsB,EAAE;IACjCJ,qBAAa,GAAGG,MAAM,CAACC,sBAAsB,CAAA;AAC/C,GAAC,MAAM;IACLD,MAAM,CAACC,sBAAsB,GAAGJ,qBAAoB,CAAA;AACtD,GAAA;AACF,CAAA;AAEO,SAASK,cAAcA,CAG5B;EAAEC,MAAM;EAAE,GAAGC,IAAAA;AAA2C,CAAC,EAAE;AAC3D;EACAD,MAAM,CAACE,MAAM,CAAC;IACZ,GAAGF,MAAM,CAACG,OAAO;AACjB,IAAA,GAA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nB,OAAO1E,QAAQ,KAAK,WAAW,GAC3BC,MAAM,CAACC,sBAAsB,IAAIJ,qBAAa,GAC9CA,qBAAa,CAAA;AACnB,EAAA,MAAMiB,KAAK,GAAGnB,gBAAK,CAAC+E,UAAU,CAACD,eAAe,CAAC,CAAA;AAC/CE,EAAAA,OAAO,CAAC7D,KAAK,EAAE,6DAA6D,CAAC,CAAA;AAC7E,EAAA,OAAOA,KAAK,CAAA;AACd;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { useStore } from '@tanstack/react-store'\nimport { Matches } from './Matches'\nimport { NavigateOptions, ResolveRelativePath, ToOptions } from './link'\nimport { ParsedLocation } from './location'\nimport { AnyRoute } from './route'\nimport { RouteById, RoutePaths } from './routeInfo'\nimport {\n BuildNextOptions,\n RegisteredRouter,\n Router,\n RouterOptions,\n RouterState,\n} from './router'\nimport { NoInfer, pick, useLayoutEffect } from './utils'\nimport { MatchRouteOptions } from './Matches'\nimport { RouteMatch } from './Matches'\n\nconst useTransition =\n React.useTransition ||\n (() => [\n false,\n (cb) => {\n cb()\n },\n ])\n\nexport interface CommitLocationOptions {\n replace?: boolean\n resetScroll?: boolean\n startTransition?: boolean\n}\n\nexport interface MatchLocation {\n to?: string | number | null\n fuzzy?: boolean\n caseSensitive?: boolean\n from?: string\n}\n\nexport type NavigateFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,\n TMaskTo extends string = '',\n>(\n opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n) => Promise<void>\n\nexport type MatchRouteFn<TRouteTree extends AnyRoute> = <\n TFrom extends RoutePaths<TRouteTree> = '/',\n TTo extends string = '',\n TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,\n>(\n location: ToOptions<TRouteTree, TFrom, TTo>,\n opts?: MatchRouteOptions,\n) => false | RouteById<TRouteTree, TResolved>['types']['allParams']\n\nexport type BuildLocationFn<TRouteTree extends AnyRoute> = (\n opts: ToOptions<TRouteTree>,\n) => ParsedLocation\n\nexport type InjectedHtmlEntry = string | (() => Promise<string> | string)\n\nexport let routerContext = React.createContext<Router<any>>(null!)\n\nif (typeof document !== 'undefined') {\n if (window.__TSR_ROUTER_CONTEXT__) {\n routerContext = window.__TSR_ROUTER_CONTEXT__\n } else {\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n }\n}\n\nexport function RouterProvider<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouteTree, TDehydrated>) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest?.context,\n },\n } as any)\n\n const matches = router.options.InnerWrap ? (\n <router.options.InnerWrap>\n <Matches />\n </router.options.InnerWrap>\n ) : (\n <Matches />\n )\n\n const provider = (\n <routerContext.Provider value={router}>\n {matches}\n <Transitioner />\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\nfunction Transitioner() {\n const mountLoadCount = React.useRef(0)\n const router = useRouter()\n const routerState = useRouterState({\n select: (s) =>\n pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning']),\n })\n\n const [isTransitioning, startReactTransition] = useTransition()\n\n router.startReactTransition = startReactTransition\n\n React.useEffect(() => {\n if (isTransitioning) {\n router.__store.setState((s) => ({\n ...s,\n isTransitioning,\n }))\n }\n }, [isTransitioning])\n\n const tryLoad = () => {\n const apply = (cb: () => void) => {\n if (!routerState.isTransitioning) {\n startReactTransition(() => cb())\n } else {\n cb()\n }\n }\n\n apply(() => {\n try {\n router.load()\n } catch (err) {\n console.error(err)\n }\n })\n }\n\n useLayoutEffect(() => {\n const unsub = router.history.subscribe(() => {\n router.latestLocation = router.parseLocation(router.latestLocation)\n if (routerState.location !== router.latestLocation) {\n tryLoad()\n }\n })\n\n const nextLocation = router.buildLocation({\n search: true,\n params: true,\n hash: true,\n state: true,\n })\n\n if (routerState.location.href !== nextLocation.href) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router.history])\n\n useLayoutEffect(() => {\n if (\n (React.useTransition as any)\n ? routerState.isTransitioning && !isTransitioning\n : true &&\n !routerState.isLoading &&\n routerState.resolvedLocation !== routerState.location\n ) {\n router.emit({\n type: 'onResolved',\n fromLocation: routerState.resolvedLocation,\n toLocation: routerState.location,\n pathChanged:\n routerState.location!.href !== routerState.resolvedLocation?.href,\n })\n\n if ((document as any).querySelector) {\n if (routerState.location.hash !== '') {\n const el = document.getElementById(\n routerState.location.hash,\n ) as HTMLElement | null\n if (el) {\n el.scrollIntoView()\n }\n }\n }\n\n router.__store.setState((s) => ({\n ...s,\n isTransitioning: false,\n resolvedLocation: s.location,\n }))\n }\n }, [\n routerState.isTransitioning,\n isTransitioning,\n routerState.isLoading,\n routerState.resolvedLocation,\n routerState.location,\n ])\n\n useLayoutEffect(() => {\n if (!window.__TSR_DEHYDRATED__ && !mountLoadCount.current) {\n mountLoadCount.current++\n tryLoad()\n }\n }, [])\n\n return null\n}\n\nexport function getRouteMatch<TRouteTree extends AnyRoute>(\n state: RouterState<TRouteTree>,\n id: string,\n): undefined | RouteMatch<TRouteTree> {\n return [\n ...state.cachedMatches,\n ...(state.pendingMatches ?? []),\n ...state.matches,\n ].find((d) => d.id === id)\n}\n\nexport function useRouterState<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TSelected = RouterState<TRouteTree>,\n>(opts?: {\n router?: Router<TRouteTree>\n select: (state: RouterState<RegisteredRouter['routeTree']>) => TSelected\n}): TSelected {\n const contextRouter = useRouter<TRouteTree>({\n warn: opts?.router === undefined,\n })\n return useStore((opts?.router || contextRouter).__store, opts?.select as any)\n}\n\nexport type RouterProps<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<RouterOptions<TRouteTree, TDehydrated>, 'context'> & {\n router: Router<TRouteTree>\n context?: Partial<RouterOptions<TRouteTree, TDehydrated>['context']>\n}\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const resolvedContext =\n typeof document !== 'undefined'\n ? window.__TSR_ROUTER_CONTEXT__ || routerContext\n : routerContext\n const value = React.useContext(resolvedContext)\n warning(\n opts?.warn && value,\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":["useTransition","React","cb","routerContext","createContext","document","window","__TSR_ROUTER_CONTEXT__","RouterProvider","router","rest","update","options","context","matches","InnerWrap","createElement","Matches","provider","Provider","value","Transitioner","Wrap","mountLoadCount","useRef","useRouter","routerState","useRouterState","select","s","pick","isTransitioning","startReactTransition","useEffect","__store","setState","tryLoad","apply","load","err","console","error","useLayoutEffect","unsub","history","subscribe","latestLocation","parseLocation","location","nextLocation","buildLocation","search","params","hash","state","href","commitLocation","replace","isLoading","resolvedLocation","emit","type","fromLocation","toLocation","pathChanged","querySelector","el","getElementById","scrollIntoView","__TSR_DEHYDRATED__","current","getRouteMatch","id","cachedMatches","pendingMatches","find","d","opts","contextRouter","warn","undefined","useStore","resolvedContext","useContext","warning"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,aAAa,GACjBC,gBAAK,CAACD,aAAa,KAClB,MAAM,CACL,KAAK,EACJE,EAAE,IAAK;AACNA,EAAAA,EAAE,EAAE,CAAA;AACN,CAAC,CACF,CAAC,CAAA;AAuCOC,qBAAa,gBAAGF,gBAAK,CAACG,aAAa,CAAc,IAAK,EAAC;AAElE,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;EACnC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C6D,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACJ,EAAE,KAAKA,EAAE,CAAC,CAAA;AAC5B,CAAA;AAEO,SAAS7C,cAAcA,CAG5BkD,IAGD,EAAa;EACZ,MAAMC,aAAa,GAAGrD,SAAS,CAAa;AAC1CsD,IAAAA,IAAI,EAAEF,IAAI,EAAEpE,MAAM,KAAKuE,SAAAA;AACzB,GAAC,CAAC,CAAA;AACF,EAAA,OAAOC,mBAAQ,CAAC,CAACJ,IAAI,EAAEpE,MAAM,IAAIqE,aAAa,EAAE5C,OAAO,EAAE2C,IAAI,EAAEjD,MAAa,CAAC,CAAA;AAC/E,CAAA;AAUO,SAASH,SAASA,CAEvBoD,IAAyB,EAAsB;AAC/C,EAAA,MAAMK,eAAe,GACnB,OAAO7E,QAAQ,KAAK,WAAW,GAC3BC,MAAM,CAACC,sBAAsB,IAAIJ,qBAAa,GAC9CA,qBAAa,CAAA;AACnB,EAAA,MAAMiB,KAAK,GAAGnB,gBAAK,CAACkF,UAAU,CAACD,eAAe,CAAC,CAAA;EAC/CE,OAAO,CACLP,IAAI,EAAEE,IAAI,IAAI3D,KAAK,EACnB,6DACF,CAAC,CAAA;AACD,EAAA,OAAOA,KAAK,CAAA;AACd;;;;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -611,13 +611,15 @@ function getRouteMatch(state, id) {
|
|
|
611
611
|
return [...state.cachedMatches, ...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
|
|
612
612
|
}
|
|
613
613
|
function useRouterState(opts) {
|
|
614
|
-
const
|
|
615
|
-
|
|
614
|
+
const contextRouter = useRouter({
|
|
615
|
+
warn: opts?.router === undefined
|
|
616
|
+
});
|
|
617
|
+
return useStore((opts?.router || contextRouter).__store, opts?.select);
|
|
616
618
|
}
|
|
617
|
-
function useRouter() {
|
|
619
|
+
function useRouter(opts) {
|
|
618
620
|
const resolvedContext = typeof document !== 'undefined' ? window.__TSR_ROUTER_CONTEXT__ || routerContext : routerContext;
|
|
619
621
|
const value = React.useContext(resolvedContext);
|
|
620
|
-
warning(value, 'useRouter must be used inside a <RouterProvider> component!');
|
|
622
|
+
warning(opts?.warn && value, 'useRouter must be used inside a <RouterProvider> component!');
|
|
621
623
|
return value;
|
|
622
624
|
}
|
|
623
625
|
|