1
1
import type { RouteObject } from "react-router" ;
2
2
import { matchRoutes } from "react-router" ;
3
3
4
- describe ( "absolute path matching" , ( ) => {
5
- function pickPaths ( routes : RouteObject [ ] , pathname : string ) {
6
- let matches = matchRoutes ( routes , { pathname } ) ;
7
- return matches ? matches . map ( match => match . route . path || "" ) : [ ] ;
8
- }
4
+ function pickPaths ( routes : RouteObject [ ] , pathname : string ) : string [ ] | null {
5
+ let matches = matchRoutes ( routes , pathname ) ;
6
+ return matches && matches . map ( match => match . route . path || "" ) ;
7
+ }
9
8
9
+ describe ( "absolute path matching" , ( ) => {
10
10
it ( "matches a nested route with an absolute path" , ( ) => {
11
11
let routes = [
12
12
{
@@ -26,6 +26,21 @@ describe("absolute path matching", () => {
26
26
expect ( pickPaths ( routes , "/users/123" ) ) . toEqual ( [ "/users" , "/users/:id" ] ) ;
27
27
} ) ;
28
28
29
+ it ( "matches a nested splat route with an absolute path" , ( ) => {
30
+ let routes = [
31
+ {
32
+ path : "/users" ,
33
+ children : [ { path : "/users/*" } ]
34
+ }
35
+ ] ;
36
+
37
+ // expect(pickPaths(routes, "/users")).toEqual(["/users"]);
38
+ expect ( pickPaths ( routes , "/users/not-found" ) ) . toEqual ( [
39
+ "/users" ,
40
+ "/users/*"
41
+ ] ) ;
42
+ } ) ;
43
+
29
44
it ( "throws when the nested path does not begin with its parent path" , ( ) => {
30
45
expect ( ( ) => {
31
46
matchRoutes (
0 commit comments