@richie-router/react 0.1.5 → 0.1.6
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/router.cjs +2 -2
- package/dist/cjs/router.test.cjs +38 -0
- package/dist/esm/router.mjs +4 -3
- package/dist/esm/router.test.mjs +38 -0
- package/dist/types/router.d.ts +0 -1
- package/package.json +2 -2
package/dist/cjs/router.cjs
CHANGED
|
@@ -541,7 +541,7 @@ class Router {
|
|
|
541
541
|
return response.head;
|
|
542
542
|
}
|
|
543
543
|
async fetchRouteHead(route, params, search) {
|
|
544
|
-
const basePath = this.
|
|
544
|
+
const basePath = prependBasePathToHref(import_core.resolveHostedRoutingConfig(this.routeTree.hostedRouting).headBasePath, this.basePath);
|
|
545
545
|
const searchParams = new URLSearchParams({
|
|
546
546
|
routeId: route.fullPath,
|
|
547
547
|
params: JSON.stringify(params),
|
|
@@ -557,7 +557,7 @@ class Router {
|
|
|
557
557
|
return await response.json();
|
|
558
558
|
}
|
|
559
559
|
async fetchDocumentHead(location) {
|
|
560
|
-
const basePath = this.
|
|
560
|
+
const basePath = prependBasePathToHref(import_core.resolveHostedRoutingConfig(this.routeTree.hostedRouting).headBasePath, this.basePath);
|
|
561
561
|
const searchParams = new URLSearchParams({
|
|
562
562
|
href: prependBasePathToHref(location.href, this.basePath)
|
|
563
563
|
});
|
package/dist/cjs/router.test.cjs
CHANGED
|
@@ -45,6 +45,12 @@ function createTestRouteTree(options) {
|
|
|
45
45
|
component: () => null
|
|
46
46
|
});
|
|
47
47
|
aboutRoute._setServerHead(options?.serverHead);
|
|
48
|
+
if (options?.headBasePath) {
|
|
49
|
+
rootRoute._setHostedRouting({
|
|
50
|
+
headBasePath: options.headBasePath,
|
|
51
|
+
passthrough: [options.headBasePath]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
48
54
|
return rootRoute._addFileChildren({
|
|
49
55
|
index: indexRoute,
|
|
50
56
|
about: aboutRoute
|
|
@@ -249,6 +255,38 @@ import_bun_test.describe("createRouter basePath", () => {
|
|
|
249
255
|
globalThis.fetch = originalFetch;
|
|
250
256
|
}
|
|
251
257
|
});
|
|
258
|
+
import_bun_test.test("uses the route tree headBasePath for document head requests", async () => {
|
|
259
|
+
const history = import_router.createMemoryHistory({
|
|
260
|
+
initialEntries: ["/project/about"]
|
|
261
|
+
});
|
|
262
|
+
const fetchCalls = [];
|
|
263
|
+
const originalFetch = globalThis.fetch;
|
|
264
|
+
globalThis.fetch = async (input) => {
|
|
265
|
+
fetchCalls.push(typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
|
|
266
|
+
return new Response(JSON.stringify({
|
|
267
|
+
head: [],
|
|
268
|
+
routeHeads: [
|
|
269
|
+
{ routeId: "/about", head: [] }
|
|
270
|
+
]
|
|
271
|
+
}), {
|
|
272
|
+
status: 200,
|
|
273
|
+
headers: {
|
|
274
|
+
"content-type": "application/json"
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
try {
|
|
279
|
+
const router = import_router.createRouter({
|
|
280
|
+
routeTree: createTestRouteTree({ serverHead: true, headBasePath: "/meta" }),
|
|
281
|
+
history,
|
|
282
|
+
basePath: "/project"
|
|
283
|
+
});
|
|
284
|
+
await router.load();
|
|
285
|
+
import_bun_test.expect(fetchCalls).toEqual(["/project/meta?href=%2Fproject%2Fabout"]);
|
|
286
|
+
} finally {
|
|
287
|
+
globalThis.fetch = originalFetch;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
252
290
|
import_bun_test.test("uses one document head request and preserves inline head precedence", async () => {
|
|
253
291
|
const history = import_router.createMemoryHistory({
|
|
254
292
|
initialEntries: ["/posts/alpha"]
|
package/dist/esm/router.mjs
CHANGED
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
matchRouteTree,
|
|
15
15
|
notFound,
|
|
16
16
|
redirect,
|
|
17
|
-
resolveHeadConfig
|
|
17
|
+
resolveHeadConfig,
|
|
18
|
+
resolveHostedRoutingConfig
|
|
18
19
|
} from "@richie-router/core";
|
|
19
20
|
import {
|
|
20
21
|
createBrowserHistory,
|
|
@@ -464,7 +465,7 @@ class Router {
|
|
|
464
465
|
return response.head;
|
|
465
466
|
}
|
|
466
467
|
async fetchRouteHead(route, params, search) {
|
|
467
|
-
const basePath = this.
|
|
468
|
+
const basePath = prependBasePathToHref(resolveHostedRoutingConfig(this.routeTree.hostedRouting).headBasePath, this.basePath);
|
|
468
469
|
const searchParams = new URLSearchParams({
|
|
469
470
|
routeId: route.fullPath,
|
|
470
471
|
params: JSON.stringify(params),
|
|
@@ -480,7 +481,7 @@ class Router {
|
|
|
480
481
|
return await response.json();
|
|
481
482
|
}
|
|
482
483
|
async fetchDocumentHead(location) {
|
|
483
|
-
const basePath = this.
|
|
484
|
+
const basePath = prependBasePathToHref(resolveHostedRoutingConfig(this.routeTree.hostedRouting).headBasePath, this.basePath);
|
|
484
485
|
const searchParams = new URLSearchParams({
|
|
485
486
|
href: prependBasePathToHref(location.href, this.basePath)
|
|
486
487
|
});
|
package/dist/esm/router.test.mjs
CHANGED
|
@@ -23,6 +23,12 @@ function createTestRouteTree(options) {
|
|
|
23
23
|
component: () => null
|
|
24
24
|
});
|
|
25
25
|
aboutRoute._setServerHead(options?.serverHead);
|
|
26
|
+
if (options?.headBasePath) {
|
|
27
|
+
rootRoute._setHostedRouting({
|
|
28
|
+
headBasePath: options.headBasePath,
|
|
29
|
+
passthrough: [options.headBasePath]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
26
32
|
return rootRoute._addFileChildren({
|
|
27
33
|
index: indexRoute,
|
|
28
34
|
about: aboutRoute
|
|
@@ -227,6 +233,38 @@ describe("createRouter basePath", () => {
|
|
|
227
233
|
globalThis.fetch = originalFetch;
|
|
228
234
|
}
|
|
229
235
|
});
|
|
236
|
+
test("uses the route tree headBasePath for document head requests", async () => {
|
|
237
|
+
const history = createMemoryHistory({
|
|
238
|
+
initialEntries: ["/project/about"]
|
|
239
|
+
});
|
|
240
|
+
const fetchCalls = [];
|
|
241
|
+
const originalFetch = globalThis.fetch;
|
|
242
|
+
globalThis.fetch = async (input) => {
|
|
243
|
+
fetchCalls.push(typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
|
|
244
|
+
return new Response(JSON.stringify({
|
|
245
|
+
head: [],
|
|
246
|
+
routeHeads: [
|
|
247
|
+
{ routeId: "/about", head: [] }
|
|
248
|
+
]
|
|
249
|
+
}), {
|
|
250
|
+
status: 200,
|
|
251
|
+
headers: {
|
|
252
|
+
"content-type": "application/json"
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
try {
|
|
257
|
+
const router = createRouter({
|
|
258
|
+
routeTree: createTestRouteTree({ serverHead: true, headBasePath: "/meta" }),
|
|
259
|
+
history,
|
|
260
|
+
basePath: "/project"
|
|
261
|
+
});
|
|
262
|
+
await router.load();
|
|
263
|
+
expect(fetchCalls).toEqual(["/project/meta?href=%2Fproject%2Fabout"]);
|
|
264
|
+
} finally {
|
|
265
|
+
globalThis.fetch = originalFetch;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
230
268
|
test("uses one document head request and preserves inline head precedence", async () => {
|
|
231
269
|
const history = createMemoryHistory({
|
|
232
270
|
initialEntries: ["/posts/alpha"]
|
package/dist/types/router.d.ts
CHANGED
|
@@ -150,7 +150,6 @@ export interface RouterOptions<TRouteTree extends AnyRoute> {
|
|
|
150
150
|
defaultErrorComponent?: AnyComponent;
|
|
151
151
|
scrollRestoration?: boolean;
|
|
152
152
|
scrollToTopSelectors?: string[];
|
|
153
|
-
headBasePath?: string;
|
|
154
153
|
trailingSlash?: 'always' | 'never' | 'preserve';
|
|
155
154
|
parseSearch?: (searchStr: string) => Record<string, unknown>;
|
|
156
155
|
stringifySearch?: (search: Record<string, unknown>) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@richie-router/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "React runtime, components, and hooks for Richie Router",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@richie-router/core": "^0.1.
|
|
16
|
+
"@richie-router/core": "^0.1.5"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^19"
|