@tanstack/react-router 1.162.1 → 1.162.4
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/RouterProvider.cjs +1 -2
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +0 -1
- package/dist/cjs/index.dev.cjs +0 -2
- package/dist/cjs/index.dev.cjs.map +1 -1
- package/dist/cjs/routerContext.cjs +1 -11
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +1 -6
- package/dist/cjs/useRouter.cjs +1 -1
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/esm/RouterProvider.js +1 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.dev.js +0 -2
- package/dist/esm/index.dev.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -6
- package/dist/esm/routerContext.js +1 -11
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/useRouter.js +2 -2
- package/dist/esm/useRouter.js.map +1 -1
- package/package.json +3 -3
- package/src/RouterProvider.tsx +1 -3
- package/src/index.tsx +0 -4
- package/src/routerContext.tsx +1 -21
- package/src/useRouter.tsx +2 -2
|
@@ -18,8 +18,7 @@ function RouterContextProvider({
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
const provider = /* @__PURE__ */ jsxRuntime.jsx(routerContext$1.Provider, { value: router, children });
|
|
21
|
+
const provider = /* @__PURE__ */ jsxRuntime.jsx(routerContext.routerContext.Provider, { value: router, children });
|
|
23
22
|
if (router.options.Wrap) {
|
|
24
23
|
return /* @__PURE__ */ jsxRuntime.jsx(router.options.Wrap, { children: provider });
|
|
25
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.cjs","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport {
|
|
1
|
+
{"version":3,"file":"RouterProvider.cjs","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { routerContext } from './routerContext'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterOptions,\n} from '@tanstack/router-core'\n\n/**\n * Low-level provider that places the router into React context and optionally\n * updates router options from props. Most apps should use `RouterProvider`.\n */\nexport function RouterContextProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({\n router,\n children,\n ...rest\n}: RouterProps<TRouter, TDehydrated> & {\n children: React.ReactNode\n}) {\n if (Object.keys(rest).length > 0) {\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 })\n }\n\n const provider = (\n <routerContext.Provider value={router as AnyRouter}>\n {children}\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\n/**\n * Top-level component that renders the active route matches and provides the\n * router to the React tree via context.\n *\n * Accepts the same options as `createRouter` via props to update the router\n * instance after creation.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction\n */\nexport function RouterProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {\n return (\n <RouterContextProvider router={router} {...rest}>\n <Matches />\n </RouterContextProvider>\n )\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >,\n 'context'\n> & {\n router: TRouter\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >['context']\n >\n}\n"],"names":["jsx","routerContext","Matches"],"mappings":";;;;;AAaO,SAAS,sBAGd;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAEG;AACD,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AAEhC,WAAO,OAAO;AAAA,MACZ,GAAG,OAAO;AAAA,MACV,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,OAAO,QAAQ;AAAA,QAClB,GAAG,KAAK;AAAA,MAAA;AAAA,IACV,CACD;AAAA,EACH;AAEA,QAAM,WACJA,2BAAAA,IAACC,4BAAc,UAAd,EAAuB,OAAO,QAC5B,UACH;AAGF,MAAI,OAAO,QAAQ,MAAM;AACvB,WAAOD,2BAAAA,IAAC,OAAO,QAAQ,MAAf,EAAqB,UAAA,UAAS;AAAA,EACxC;AAEA,SAAO;AACT;AAWO,SAAS,eAGd,EAAE,QAAQ,GAAG,QAA2C;AACxD,wCACG,uBAAA,EAAsB,QAAiB,GAAG,MACzC,UAAAA,+BAACE,QAAAA,WAAQ,GACX;AAEJ;;;"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -22,7 +22,6 @@ const useBlocker = require("./useBlocker.cjs");
|
|
|
22
22
|
const useNavigate = require("./useNavigate.cjs");
|
|
23
23
|
const useParams = require("./useParams.cjs");
|
|
24
24
|
const useSearch = require("./useSearch.cjs");
|
|
25
|
-
const routerContext = require("./routerContext.cjs");
|
|
26
25
|
const useRouteContext = require("./useRouteContext.cjs");
|
|
27
26
|
const useRouter = require("./useRouter.cjs");
|
|
28
27
|
const useRouterState = require("./useRouterState.cjs");
|
|
@@ -250,7 +249,6 @@ exports.Navigate = useNavigate.Navigate;
|
|
|
250
249
|
exports.useNavigate = useNavigate.useNavigate;
|
|
251
250
|
exports.useParams = useParams.useParams;
|
|
252
251
|
exports.useSearch = useSearch.useSearch;
|
|
253
|
-
exports.getRouterContext = routerContext.getRouterContext;
|
|
254
252
|
exports.useRouteContext = useRouteContext.useRouteContext;
|
|
255
253
|
exports.useRouter = useRouter.useRouter;
|
|
256
254
|
exports.useRouterState = useRouterState.useRouterState;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -32,7 +32,6 @@ export { useBlocker, Block } from './useBlocker.cjs';
|
|
|
32
32
|
export { useNavigate, Navigate } from './useNavigate.cjs';
|
|
33
33
|
export { useParams } from './useParams.cjs';
|
|
34
34
|
export { useSearch } from './useSearch.cjs';
|
|
35
|
-
export { getRouterContext, } from './routerContext.cjs';
|
|
36
35
|
export { useRouteContext } from './useRouteContext.cjs';
|
|
37
36
|
export { useRouter } from './useRouter.cjs';
|
|
38
37
|
export { useRouterState } from './useRouterState.cjs';
|
package/dist/cjs/index.dev.cjs
CHANGED
|
@@ -22,7 +22,6 @@ const useBlocker = require("./useBlocker.cjs");
|
|
|
22
22
|
const useNavigate = require("./useNavigate.cjs");
|
|
23
23
|
const useParams = require("./useParams.cjs");
|
|
24
24
|
const useSearch = require("./useSearch.cjs");
|
|
25
|
-
const routerContext = require("./routerContext.cjs");
|
|
26
25
|
const useRouteContext = require("./useRouteContext.cjs");
|
|
27
26
|
const useRouter = require("./useRouter.cjs");
|
|
28
27
|
const useRouterState = require("./useRouterState.cjs");
|
|
@@ -250,7 +249,6 @@ exports.Navigate = useNavigate.Navigate;
|
|
|
250
249
|
exports.useNavigate = useNavigate.useNavigate;
|
|
251
250
|
exports.useParams = useParams.useParams;
|
|
252
251
|
exports.useSearch = useSearch.useSearch;
|
|
253
|
-
exports.getRouterContext = routerContext.getRouterContext;
|
|
254
252
|
exports.useRouteContext = useRouteContext.useRouteContext;
|
|
255
253
|
exports.useRouter = useRouter.useRouter;
|
|
256
254
|
exports.useRouterState = useRouterState.useRouterState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.dev.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.dev.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -19,15 +19,5 @@ function _interopNamespaceDefault(e) {
|
|
|
19
19
|
}
|
|
20
20
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
21
21
|
const routerContext = React__namespace.createContext(null);
|
|
22
|
-
|
|
23
|
-
if (typeof document === "undefined") {
|
|
24
|
-
return routerContext;
|
|
25
|
-
}
|
|
26
|
-
if (window.__TSR_ROUTER_CONTEXT__) {
|
|
27
|
-
return window.__TSR_ROUTER_CONTEXT__;
|
|
28
|
-
}
|
|
29
|
-
window.__TSR_ROUTER_CONTEXT__ = routerContext;
|
|
30
|
-
return routerContext;
|
|
31
|
-
}
|
|
32
|
-
exports.getRouterContext = getRouterContext;
|
|
22
|
+
exports.routerContext = routerContext;
|
|
33
23
|
//# sourceMappingURL=routerContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerContext.cjs","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\
|
|
1
|
+
{"version":3,"file":"routerContext.cjs","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const routerContext = React.createContext<AnyRouter>(null!)\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,MAAM,gBAAgBA,iBAAM,cAAyB,IAAK;;"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { AnyRouter } from '@tanstack/router-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
declare
|
|
4
|
-
interface Window {
|
|
5
|
-
__TSR_ROUTER_CONTEXT__?: React.Context<AnyRouter>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export declare function getRouterContext(): React.Context<AnyRouter>;
|
|
3
|
+
export declare const routerContext: React.Context<AnyRouter>;
|
package/dist/cjs/useRouter.cjs
CHANGED
|
@@ -21,7 +21,7 @@ function _interopNamespaceDefault(e) {
|
|
|
21
21
|
}
|
|
22
22
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
23
|
function useRouter(opts) {
|
|
24
|
-
const value = React__namespace.useContext(routerContext.
|
|
24
|
+
const value = React__namespace.useContext(routerContext.routerContext);
|
|
25
25
|
warning(
|
|
26
26
|
!((opts?.warn ?? true) && !value),
|
|
27
27
|
"useRouter must be used inside a <RouterProvider> component!"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.cjs","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport {
|
|
1
|
+
{"version":3,"file":"useRouter.cjs","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":["React","routerContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeO,SAAS,UAAwD,MAE5D;AACV,QAAM,QAAQA,iBAAM,WAAWC,2BAAa;AAC5C;AAAA,IACE,GAAG,MAAM,QAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEF,SAAO;AACT;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Matches } from "./Matches.js";
|
|
3
|
-
import {
|
|
3
|
+
import { routerContext } from "./routerContext.js";
|
|
4
4
|
function RouterContextProvider({
|
|
5
5
|
router,
|
|
6
6
|
children,
|
|
@@ -16,7 +16,6 @@ function RouterContextProvider({
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
const routerContext = getRouterContext();
|
|
20
19
|
const provider = /* @__PURE__ */ jsx(routerContext.Provider, { value: router, children });
|
|
21
20
|
if (router.options.Wrap) {
|
|
22
21
|
return /* @__PURE__ */ jsx(router.options.Wrap, { children: provider });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport {
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","sources":["../../src/RouterProvider.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Matches } from './Matches'\nimport { routerContext } from './routerContext'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterOptions,\n} from '@tanstack/router-core'\n\n/**\n * Low-level provider that places the router into React context and optionally\n * updates router options from props. Most apps should use `RouterProvider`.\n */\nexport function RouterContextProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({\n router,\n children,\n ...rest\n}: RouterProps<TRouter, TDehydrated> & {\n children: React.ReactNode\n}) {\n if (Object.keys(rest).length > 0) {\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 })\n }\n\n const provider = (\n <routerContext.Provider value={router as AnyRouter}>\n {children}\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\n/**\n * Top-level component that renders the active route matches and provides the\n * router to the React tree via context.\n *\n * Accepts the same options as `createRouter` via props to update the router\n * instance after creation.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction\n */\nexport function RouterProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {\n return (\n <RouterContextProvider router={router} {...rest}>\n <Matches />\n </RouterContextProvider>\n )\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >,\n 'context'\n> & {\n router: TRouter\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >['context']\n >\n}\n"],"names":[],"mappings":";;;AAaO,SAAS,sBAGd;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAEG;AACD,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AAEhC,WAAO,OAAO;AAAA,MACZ,GAAG,OAAO;AAAA,MACV,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,OAAO,QAAQ;AAAA,QAClB,GAAG,KAAK;AAAA,MAAA;AAAA,IACV,CACD;AAAA,EACH;AAEA,QAAM,WACJ,oBAAC,cAAc,UAAd,EAAuB,OAAO,QAC5B,UACH;AAGF,MAAI,OAAO,QAAQ,MAAM;AACvB,WAAO,oBAAC,OAAO,QAAQ,MAAf,EAAqB,UAAA,UAAS;AAAA,EACxC;AAEA,SAAO;AACT;AAWO,SAAS,eAGd,EAAE,QAAQ,GAAG,QAA2C;AACxD,6BACG,uBAAA,EAAsB,QAAiB,GAAG,MACzC,UAAA,oBAAC,WAAQ,GACX;AAEJ;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export { useBlocker, Block } from './useBlocker.js';
|
|
|
32
32
|
export { useNavigate, Navigate } from './useNavigate.js';
|
|
33
33
|
export { useParams } from './useParams.js';
|
|
34
34
|
export { useSearch } from './useSearch.js';
|
|
35
|
-
export { getRouterContext, } from './routerContext.js';
|
|
36
35
|
export { useRouteContext } from './useRouteContext.js';
|
|
37
36
|
export { useRouter } from './useRouter.js';
|
|
38
37
|
export { useRouterState } from './useRouterState.js';
|
package/dist/esm/index.dev.js
CHANGED
|
@@ -20,7 +20,6 @@ import { Block, useBlocker } from "./useBlocker.js";
|
|
|
20
20
|
import { Navigate, useNavigate } from "./useNavigate.js";
|
|
21
21
|
import { useParams } from "./useParams.js";
|
|
22
22
|
import { useSearch } from "./useSearch.js";
|
|
23
|
-
import { getRouterContext } from "./routerContext.js";
|
|
24
23
|
import { useRouteContext } from "./useRouteContext.js";
|
|
25
24
|
import { useRouter } from "./useRouter.js";
|
|
26
25
|
import { useRouterState } from "./useRouterState.js";
|
|
@@ -93,7 +92,6 @@ export {
|
|
|
93
92
|
functionalUpdate,
|
|
94
93
|
getInitialRouterState,
|
|
95
94
|
getRouteApi,
|
|
96
|
-
getRouterContext,
|
|
97
95
|
interpolatePath,
|
|
98
96
|
isMatch,
|
|
99
97
|
isNotFound,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.dev.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.dev.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import { Block, useBlocker } from "./useBlocker.js";
|
|
|
20
20
|
import { Navigate, useNavigate } from "./useNavigate.js";
|
|
21
21
|
import { useParams } from "./useParams.js";
|
|
22
22
|
import { useSearch } from "./useSearch.js";
|
|
23
|
-
import { getRouterContext } from "./routerContext.js";
|
|
24
23
|
import { useRouteContext } from "./useRouteContext.js";
|
|
25
24
|
import { useRouter } from "./useRouter.js";
|
|
26
25
|
import { useRouterState } from "./useRouterState.js";
|
|
@@ -93,7 +92,6 @@ export {
|
|
|
93
92
|
functionalUpdate,
|
|
94
93
|
getInitialRouterState,
|
|
95
94
|
getRouteApi,
|
|
96
|
-
getRouterContext,
|
|
97
95
|
interpolatePath,
|
|
98
96
|
isMatch,
|
|
99
97
|
isNotFound,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { AnyRouter } from '@tanstack/router-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
declare
|
|
4
|
-
interface Window {
|
|
5
|
-
__TSR_ROUTER_CONTEXT__?: React.Context<AnyRouter>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export declare function getRouterContext(): React.Context<AnyRouter>;
|
|
3
|
+
export declare const routerContext: React.Context<AnyRouter>;
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
const routerContext = React.createContext(null);
|
|
3
|
-
function getRouterContext() {
|
|
4
|
-
if (typeof document === "undefined") {
|
|
5
|
-
return routerContext;
|
|
6
|
-
}
|
|
7
|
-
if (window.__TSR_ROUTER_CONTEXT__) {
|
|
8
|
-
return window.__TSR_ROUTER_CONTEXT__;
|
|
9
|
-
}
|
|
10
|
-
window.__TSR_ROUTER_CONTEXT__ = routerContext;
|
|
11
|
-
return routerContext;
|
|
12
|
-
}
|
|
13
3
|
export {
|
|
14
|
-
|
|
4
|
+
routerContext
|
|
15
5
|
};
|
|
16
6
|
//# sourceMappingURL=routerContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\
|
|
1
|
+
{"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { AnyRouter } from '@tanstack/router-core'\n\nexport const routerContext = React.createContext<AnyRouter>(null!)\n"],"names":[],"mappings":";AAGO,MAAM,gBAAgB,MAAM,cAAyB,IAAK;"}
|
package/dist/esm/useRouter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import warning from "tiny-warning";
|
|
3
|
-
import {
|
|
3
|
+
import { routerContext } from "./routerContext.js";
|
|
4
4
|
function useRouter(opts) {
|
|
5
|
-
const value = React.useContext(
|
|
5
|
+
const value = React.useContext(routerContext);
|
|
6
6
|
warning(
|
|
7
7
|
!((opts?.warn ?? true) && !value),
|
|
8
8
|
"useRouter must be used inside a <RouterProvider> component!"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport {
|
|
1
|
+
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { routerContext } from './routerContext'\nimport type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'\n\n/**\n * Access the current TanStack Router instance from React context.\n * Must be used within a `RouterProvider`.\n *\n * Options:\n * - `warn`: Log a warning if no router context is found (default: true).\n *\n * @returns The registered router instance.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterHook\n */\nexport function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {\n warn?: boolean\n}): TRouter {\n const value = React.useContext(routerContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":[],"mappings":";;;AAeO,SAAS,UAAwD,MAE5D;AACV,QAAM,QAAQ,MAAM,WAAW,aAAa;AAC5C;AAAA,IACE,GAAG,MAAM,QAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEF,SAAO;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.162.
|
|
3
|
+
"version": "1.162.4",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"isbot": "^5.1.22",
|
|
82
82
|
"tiny-invariant": "^1.3.3",
|
|
83
83
|
"tiny-warning": "^1.0.3",
|
|
84
|
-
"@tanstack/
|
|
85
|
-
"@tanstack/
|
|
84
|
+
"@tanstack/router-core": "1.162.2",
|
|
85
|
+
"@tanstack/history": "1.161.4"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { Matches } from './Matches'
|
|
3
|
-
import {
|
|
3
|
+
import { routerContext } from './routerContext'
|
|
4
4
|
import type {
|
|
5
5
|
AnyRouter,
|
|
6
6
|
RegisteredRouter,
|
|
@@ -33,8 +33,6 @@ export function RouterContextProvider<
|
|
|
33
33
|
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const routerContext = getRouterContext()
|
|
37
|
-
|
|
38
36
|
const provider = (
|
|
39
37
|
<routerContext.Provider value={router as AnyRouter}>
|
|
40
38
|
{children}
|
package/src/index.tsx
CHANGED
|
@@ -298,10 +298,6 @@ export { useNavigate, Navigate } from './useNavigate'
|
|
|
298
298
|
export { useParams } from './useParams'
|
|
299
299
|
export { useSearch } from './useSearch'
|
|
300
300
|
|
|
301
|
-
export {
|
|
302
|
-
getRouterContext, // SSR
|
|
303
|
-
} from './routerContext'
|
|
304
|
-
|
|
305
301
|
export { useRouteContext } from './useRouteContext'
|
|
306
302
|
export { useRouter } from './useRouter'
|
|
307
303
|
export { useRouterState } from './useRouterState'
|
package/src/routerContext.tsx
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import type { AnyRouter } from '@tanstack/router-core'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
interface Window {
|
|
6
|
-
__TSR_ROUTER_CONTEXT__?: React.Context<AnyRouter>
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const routerContext = React.createContext<AnyRouter>(null!)
|
|
11
|
-
|
|
12
|
-
export function getRouterContext() {
|
|
13
|
-
if (typeof document === 'undefined') {
|
|
14
|
-
return routerContext
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (window.__TSR_ROUTER_CONTEXT__) {
|
|
18
|
-
return window.__TSR_ROUTER_CONTEXT__
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
window.__TSR_ROUTER_CONTEXT__ = routerContext as any
|
|
22
|
-
|
|
23
|
-
return routerContext
|
|
24
|
-
}
|
|
4
|
+
export const routerContext = React.createContext<AnyRouter>(null!)
|
package/src/useRouter.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import warning from 'tiny-warning'
|
|
3
|
-
import {
|
|
3
|
+
import { routerContext } from './routerContext'
|
|
4
4
|
import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -16,7 +16,7 @@ import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core'
|
|
|
16
16
|
export function useRouter<TRouter extends AnyRouter = RegisteredRouter>(opts?: {
|
|
17
17
|
warn?: boolean
|
|
18
18
|
}): TRouter {
|
|
19
|
-
const value = React.useContext(
|
|
19
|
+
const value = React.useContext(routerContext)
|
|
20
20
|
warning(
|
|
21
21
|
!((opts?.warn ?? true) && !value),
|
|
22
22
|
'useRouter must be used inside a <RouterProvider> component!',
|