@richie-router/react 0.1.4 → 0.1.5
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.test.cjs +37 -0
- package/dist/esm/router.test.mjs +37 -0
- package/package.json +2 -2
package/dist/cjs/router.test.cjs
CHANGED
|
@@ -129,6 +129,21 @@ function createLinkTestRouteTree(component) {
|
|
|
129
129
|
posts: postsRoute
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
+
function createStaticAndDynamicSiblingRouteTree() {
|
|
133
|
+
const rootRoute = import_router.createRootRoute({
|
|
134
|
+
component: () => null
|
|
135
|
+
});
|
|
136
|
+
const registerRoute = import_router.createFileRoute("/register")({
|
|
137
|
+
component: () => null
|
|
138
|
+
});
|
|
139
|
+
const usernameRoute = import_router.createFileRoute("/$username")({
|
|
140
|
+
component: () => null
|
|
141
|
+
});
|
|
142
|
+
return rootRoute._addFileChildren({
|
|
143
|
+
register: registerRoute,
|
|
144
|
+
username: usernameRoute
|
|
145
|
+
});
|
|
146
|
+
}
|
|
132
147
|
function renderLinkMarkup(initialEntry, component) {
|
|
133
148
|
const history = import_router.createMemoryHistory({
|
|
134
149
|
initialEntries: [initialEntry]
|
|
@@ -534,6 +549,28 @@ import_bun_test.describe("Link active state", () => {
|
|
|
534
549
|
import_bun_test.expect(markup).not.toContain('class="active"');
|
|
535
550
|
});
|
|
536
551
|
});
|
|
552
|
+
import_bun_test.describe("route matching precedence", () => {
|
|
553
|
+
import_bun_test.test("prefers a static sibling over a dynamic sibling", () => {
|
|
554
|
+
const router = import_router.createRouter({
|
|
555
|
+
routeTree: createStaticAndDynamicSiblingRouteTree(),
|
|
556
|
+
history: import_router.createMemoryHistory({
|
|
557
|
+
initialEntries: ["/register"]
|
|
558
|
+
})
|
|
559
|
+
});
|
|
560
|
+
import_bun_test.expect(router.state.matches.at(-1)?.route.fullPath).toBe("/register");
|
|
561
|
+
import_bun_test.expect(router.state.matches.at(-1)?.params).toEqual({});
|
|
562
|
+
});
|
|
563
|
+
import_bun_test.test("falls back to the dynamic sibling when no static sibling matches", () => {
|
|
564
|
+
const router = import_router.createRouter({
|
|
565
|
+
routeTree: createStaticAndDynamicSiblingRouteTree(),
|
|
566
|
+
history: import_router.createMemoryHistory({
|
|
567
|
+
initialEntries: ["/richie"]
|
|
568
|
+
})
|
|
569
|
+
});
|
|
570
|
+
import_bun_test.expect(router.state.matches.at(-1)?.route.fullPath).toBe("/$username");
|
|
571
|
+
import_bun_test.expect(router.state.matches.at(-1)?.params).toEqual({ username: "richie" });
|
|
572
|
+
});
|
|
573
|
+
});
|
|
537
574
|
import_bun_test.describe("useMatchRoute", () => {
|
|
538
575
|
import_bun_test.test("returns matched params for exact matches", () => {
|
|
539
576
|
const markup = renderLinkMarkup("/posts/alpha", () => {
|
package/dist/esm/router.test.mjs
CHANGED
|
@@ -107,6 +107,21 @@ function createLinkTestRouteTree(component) {
|
|
|
107
107
|
posts: postsRoute
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
+
function createStaticAndDynamicSiblingRouteTree() {
|
|
111
|
+
const rootRoute = createRootRoute({
|
|
112
|
+
component: () => null
|
|
113
|
+
});
|
|
114
|
+
const registerRoute = createFileRoute("/register")({
|
|
115
|
+
component: () => null
|
|
116
|
+
});
|
|
117
|
+
const usernameRoute = createFileRoute("/$username")({
|
|
118
|
+
component: () => null
|
|
119
|
+
});
|
|
120
|
+
return rootRoute._addFileChildren({
|
|
121
|
+
register: registerRoute,
|
|
122
|
+
username: usernameRoute
|
|
123
|
+
});
|
|
124
|
+
}
|
|
110
125
|
function renderLinkMarkup(initialEntry, component) {
|
|
111
126
|
const history = createMemoryHistory({
|
|
112
127
|
initialEntries: [initialEntry]
|
|
@@ -512,6 +527,28 @@ describe("Link active state", () => {
|
|
|
512
527
|
expect(markup).not.toContain('class="active"');
|
|
513
528
|
});
|
|
514
529
|
});
|
|
530
|
+
describe("route matching precedence", () => {
|
|
531
|
+
test("prefers a static sibling over a dynamic sibling", () => {
|
|
532
|
+
const router = createRouter({
|
|
533
|
+
routeTree: createStaticAndDynamicSiblingRouteTree(),
|
|
534
|
+
history: createMemoryHistory({
|
|
535
|
+
initialEntries: ["/register"]
|
|
536
|
+
})
|
|
537
|
+
});
|
|
538
|
+
expect(router.state.matches.at(-1)?.route.fullPath).toBe("/register");
|
|
539
|
+
expect(router.state.matches.at(-1)?.params).toEqual({});
|
|
540
|
+
});
|
|
541
|
+
test("falls back to the dynamic sibling when no static sibling matches", () => {
|
|
542
|
+
const router = createRouter({
|
|
543
|
+
routeTree: createStaticAndDynamicSiblingRouteTree(),
|
|
544
|
+
history: createMemoryHistory({
|
|
545
|
+
initialEntries: ["/richie"]
|
|
546
|
+
})
|
|
547
|
+
});
|
|
548
|
+
expect(router.state.matches.at(-1)?.route.fullPath).toBe("/$username");
|
|
549
|
+
expect(router.state.matches.at(-1)?.params).toEqual({ username: "richie" });
|
|
550
|
+
});
|
|
551
|
+
});
|
|
515
552
|
describe("useMatchRoute", () => {
|
|
516
553
|
test("returns matched params for exact matches", () => {
|
|
517
554
|
const markup = renderLinkMarkup("/posts/alpha", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@richie-router/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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.4"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^19"
|