Skip to content

Commit 8ca5f32

Browse files
committed
adding changeset and fixing test
1 parent 6b3d08e commit 8ca5f32

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

.changeset/ninety-penguins-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-resource-router": patch
3+
---
4+
5+
Supporting navigation to / and basePath when basePath is defined

src/common/utils/match-route/test.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,25 @@ describe('matchRoute()', () => {
156156
).toMatchObject({
157157
route: routeA,
158158
});
159+
159160
expect(
160161
// @ts-ignore
161-
matchRoute([routeB, routeA], '/base/abc', DEFAULT_QUERY_PARAMS, basePath)
162+
matchRoute([routeB, routeA], '/base/def', DEFAULT_QUERY_PARAMS, basePath)
162163
).toMatchObject({
163164
route: routeB,
164165
});
165166
});
166167

167168
it('should ignore basePath when navigating to just basePath', () => {
168169
const routeA = { path: '/base', component: Noop };
169-
const routeB = { path: '/:bar', component: Noop };
170+
const routeB = { path: '/', component: Noop };
171+
const routeC = { path: '/:bar', component: Noop };
170172
const basePath = '/base';
171173
expect(
172174
matchRoute(
173175
// @ts-ignore
174-
[routeA, routeB],
175-
'/base',
176+
[routeA, routeB, routeC],
177+
basePath,
176178
DEFAULT_QUERY_PARAMS,
177179
basePath
178180
)
@@ -181,16 +183,36 @@ describe('matchRoute()', () => {
181183
});
182184

183185
expect(
184-
// @ts-ignore
185-
matchRoute([routeA, routeB], '/abc', DEFAULT_QUERY_PARAMS, basePath)
186-
).toBeNull();
186+
matchRoute(
187+
// @ts-ignore
188+
[routeA, routeB, routeC],
189+
'/base/base',
190+
DEFAULT_QUERY_PARAMS,
191+
basePath
192+
)
193+
).toMatchObject({
194+
route: routeA,
195+
});
187196

188197
expect(
189-
// @ts-ignore
190-
matchRoute([routeA, routeB], '/base/abc', DEFAULT_QUERY_PARAMS, basePath)
198+
matchRoute(
199+
// @ts-ignore
200+
[routeC, routeA, routeB],
201+
'/base/',
202+
DEFAULT_QUERY_PARAMS,
203+
basePath
204+
)
191205
).toMatchObject({
192206
route: routeB,
193207
});
208+
209+
expect(
210+
// @ts-ignore
211+
matchRoute([routeA, routeC, routeB], '/base/abc', DEFAULT_QUERY_PARAMS, basePath)
212+
).toMatchObject({
213+
route: routeC,
214+
});
215+
194216
});
195217
});
196218

0 commit comments

Comments
 (0)