@tanstack/react-router 1.12.9 → 1.12.11
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 +3 -4
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/path.cjs +6 -2
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/router.cjs +3 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/routerContext.cjs +9 -5
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerContext.d.cts +1 -1
- package/dist/cjs/useRouter.cjs +1 -2
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/esm/RouterProvider.js +3 -4
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/path.js +6 -2
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/router.js +3 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.d.ts +1 -1
- package/dist/esm/routerContext.js +8 -5
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/useRouter.js +2 -3
- package/dist/esm/useRouter.js.map +1 -1
- package/package.json +1 -1
- package/src/RouterProvider.tsx +6 -4
- package/src/path.ts +6 -2
- package/src/router.ts +3 -2
- package/src/routerContext.tsx +12 -5
- package/src/useRouter.tsx +2 -6
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Router } from './router';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function getRouterContext(): React.Context<Router<any, Record<string, any>, Record<string, any>>>;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
let routerContext = React.createContext(null);
|
|
3
|
-
|
|
3
|
+
function getRouterContext() {
|
|
4
|
+
if (typeof document === "undefined") {
|
|
5
|
+
return routerContext;
|
|
6
|
+
}
|
|
4
7
|
if (window.__TSR_ROUTER_CONTEXT__) {
|
|
5
|
-
|
|
6
|
-
} else {
|
|
7
|
-
window.__TSR_ROUTER_CONTEXT__ = routerContext;
|
|
8
|
+
return window.__TSR_ROUTER_CONTEXT__;
|
|
8
9
|
}
|
|
10
|
+
window.__TSR_ROUTER_CONTEXT__ = routerContext;
|
|
11
|
+
return routerContext;
|
|
9
12
|
}
|
|
10
13
|
export {
|
|
11
|
-
|
|
14
|
+
getRouterContext
|
|
12
15
|
};
|
|
13
16
|
//# sourceMappingURL=routerContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Router } from './router'\n\
|
|
1
|
+
{"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Router } from './router'\n\nlet routerContext = React.createContext<Router<any>>(null!)\n\nexport function getRouterContext() {\n if (typeof document === 'undefined') {\n return routerContext\n }\n\n if (window.__TSR_ROUTER_CONTEXT__) {\n return window.__TSR_ROUTER_CONTEXT__\n }\n\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n\n return routerContext\n}\n"],"names":[],"mappings":";AAGA,IAAI,gBAAgB,MAAM,cAA2B,IAAK;AAEnD,SAAS,mBAAmB;AAC7B,MAAA,OAAO,aAAa,aAAa;AAC5B,WAAA;AAAA,EACT;AAEA,MAAI,OAAO,wBAAwB;AACjC,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,yBAAyB;AAEzB,SAAA;AACT;"}
|
package/dist/esm/useRouter.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import warning from "tiny-warning";
|
|
3
|
-
import {
|
|
3
|
+
import { getRouterContext } from "./routerContext.js";
|
|
4
4
|
function useRouter(opts) {
|
|
5
|
-
const
|
|
6
|
-
const value = React.useContext(resolvedContext);
|
|
5
|
+
const value = React.useContext(getRouterContext());
|
|
7
6
|
warning(
|
|
8
7
|
!(((opts == null ? void 0 : opts.warn) ?? true) && !value),
|
|
9
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 { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport {
|
|
1
|
+
{"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport { getRouterContext } from './routerContext'\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const value = React.useContext(getRouterContext())\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":";;;AAMO,SAAS,UAEd,MAA+C;AAC/C,QAAM,QAAQ,MAAM,WAAW,iBAAkB,CAAA;AACjD;AAAA,IACE,IAAG,6BAAM,SAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEK,SAAA;AACT;"}
|
package/package.json
CHANGED
package/src/RouterProvider.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import { pick, useLayoutEffect } from './utils'
|
|
|
10
10
|
import { RouteMatch } from './Matches'
|
|
11
11
|
import { useRouter } from './useRouter'
|
|
12
12
|
import { useRouterState } from './useRouterState'
|
|
13
|
-
import {
|
|
13
|
+
import { getRouterContext } from './routerContext'
|
|
14
14
|
|
|
15
15
|
const useTransition =
|
|
16
16
|
React.useTransition ||
|
|
@@ -78,6 +78,8 @@ export function RouterProvider<
|
|
|
78
78
|
<Matches />
|
|
79
79
|
)
|
|
80
80
|
|
|
81
|
+
const routerContext = getRouterContext()
|
|
82
|
+
|
|
81
83
|
const provider = (
|
|
82
84
|
<routerContext.Provider value={router}>
|
|
83
85
|
{matches}
|
|
@@ -197,10 +199,10 @@ function Transitioner() {
|
|
|
197
199
|
])
|
|
198
200
|
|
|
199
201
|
useLayoutEffect(() => {
|
|
200
|
-
if (window.__TSR_DEHYDRATED__) return
|
|
201
202
|
if (
|
|
202
|
-
|
|
203
|
-
mountLoadForRouter.current.
|
|
203
|
+
window.__TSR_DEHYDRATED__ ||
|
|
204
|
+
(mountLoadForRouter.current.router === router &&
|
|
205
|
+
mountLoadForRouter.current.mounted)
|
|
204
206
|
) {
|
|
205
207
|
return
|
|
206
208
|
}
|
package/src/path.ts
CHANGED
|
@@ -220,7 +220,9 @@ export function matchByPath(
|
|
|
220
220
|
if (routeSegment) {
|
|
221
221
|
if (routeSegment.type === 'wildcard') {
|
|
222
222
|
if (baseSegment?.value) {
|
|
223
|
-
const _splat =
|
|
223
|
+
const _splat = decodeURI(
|
|
224
|
+
joinPaths(baseSegments.slice(i).map((d) => d.value)),
|
|
225
|
+
)
|
|
224
226
|
// TODO: Deprecate *
|
|
225
227
|
params['*'] = _splat
|
|
226
228
|
params['_splat'] = _splat
|
|
@@ -257,7 +259,9 @@ export function matchByPath(
|
|
|
257
259
|
return false
|
|
258
260
|
}
|
|
259
261
|
if (baseSegment.value.charAt(0) !== '$') {
|
|
260
|
-
params[routeSegment.value.substring(1)] =
|
|
262
|
+
params[routeSegment.value.substring(1)] = decodeURI(
|
|
263
|
+
baseSegment.value,
|
|
264
|
+
)
|
|
261
265
|
}
|
|
262
266
|
}
|
|
263
267
|
}
|
package/src/router.ts
CHANGED
|
@@ -509,13 +509,14 @@ export class Router<
|
|
|
509
509
|
state,
|
|
510
510
|
}: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => {
|
|
511
511
|
const parsedSearch = this.options.parseSearch(search)
|
|
512
|
+
const searchStr = this.options.stringifySearch(parsedSearch)
|
|
512
513
|
|
|
513
514
|
return {
|
|
514
515
|
pathname: pathname,
|
|
515
|
-
searchStr
|
|
516
|
+
searchStr,
|
|
516
517
|
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
|
|
517
518
|
hash: hash.split('#').reverse()[0] ?? '',
|
|
518
|
-
href: `${pathname}${
|
|
519
|
+
href: `${pathname}${searchStr}${hash}`,
|
|
519
520
|
state: replaceEqualDeep(previousLocation?.state, state) as HistoryState,
|
|
520
521
|
}
|
|
521
522
|
}
|
package/src/routerContext.tsx
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { Router } from './router'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let routerContext = React.createContext<Router<any>>(null!)
|
|
5
|
+
|
|
6
|
+
export function getRouterContext() {
|
|
7
|
+
if (typeof document === 'undefined') {
|
|
8
|
+
return routerContext
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
if (window.__TSR_ROUTER_CONTEXT__) {
|
|
7
|
-
|
|
8
|
-
} else {
|
|
9
|
-
window.__TSR_ROUTER_CONTEXT__ = routerContext as any
|
|
12
|
+
return window.__TSR_ROUTER_CONTEXT__
|
|
10
13
|
}
|
|
14
|
+
|
|
15
|
+
window.__TSR_ROUTER_CONTEXT__ = routerContext as any
|
|
16
|
+
|
|
17
|
+
return routerContext
|
|
11
18
|
}
|
package/src/useRouter.tsx
CHANGED
|
@@ -2,16 +2,12 @@ import * as React from 'react'
|
|
|
2
2
|
import warning from 'tiny-warning'
|
|
3
3
|
import { AnyRoute } from './route'
|
|
4
4
|
import { RegisteredRouter, Router } from './router'
|
|
5
|
-
import {
|
|
5
|
+
import { getRouterContext } from './routerContext'
|
|
6
6
|
|
|
7
7
|
export function useRouter<
|
|
8
8
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
9
9
|
>(opts?: { warn?: boolean }): Router<TRouteTree> {
|
|
10
|
-
const
|
|
11
|
-
typeof document !== 'undefined'
|
|
12
|
-
? window.__TSR_ROUTER_CONTEXT__ || routerContext
|
|
13
|
-
: routerContext
|
|
14
|
-
const value = React.useContext(resolvedContext)
|
|
10
|
+
const value = React.useContext(getRouterContext())
|
|
15
11
|
warning(
|
|
16
12
|
!((opts?.warn ?? true) && !value),
|
|
17
13
|
'useRouter must be used inside a <RouterProvider> component!',
|