@@ -8,14 +8,27 @@ import React from 'react';
8
8
9
9
import { Action , Location } from './types' ;
10
10
11
- interface RouteObject {
11
+ interface NonIndexRouteObject {
12
12
caseSensitive ?: boolean ;
13
13
children ?: RouteObject [ ] ;
14
- element ?: React . ReactNode ;
15
- index ?: boolean ;
14
+ element ?: React . ReactNode | null ;
15
+ index ?: false ;
16
16
path ?: string ;
17
17
}
18
18
19
+ interface IndexRouteObject {
20
+ caseSensitive ?: boolean ;
21
+ children ?: undefined ;
22
+ element ?: React . ReactNode | null ;
23
+ index ?: true ;
24
+ path ?: string ;
25
+ }
26
+
27
+ // This type was originally just `type RouteObject = IndexRouteObject`, but this was changed
28
+ // in https://github.com/remix-run/react-router/pull/9366, which was released with `6.4.2`
29
+ // See https://github.com/remix-run/react-router/issues/9427 for a discussion on this.
30
+ type RouteObject = IndexRouteObject | NonIndexRouteObject ;
31
+
19
32
type Params < Key extends string = string > = {
20
33
readonly [ key in Key ] : string | undefined ;
21
34
} ;
@@ -45,8 +58,16 @@ interface RouteMatch<ParamKey extends string = string> {
45
58
type UseEffect = ( cb : ( ) => void , deps : unknown [ ] ) => void ;
46
59
type UseLocation = ( ) => Location ;
47
60
type UseNavigationType = ( ) => Action ;
48
- type CreateRoutesFromChildren = ( children : JSX . Element [ ] ) => RouteObject [ ] ;
49
- type MatchRoutes = ( routes : RouteObject [ ] , location : Location ) => RouteMatch [ ] | null ;
61
+
62
+ // For both of these types, use `any` instead of `RouteObject[]` or `RouteMatch[]`.
63
+ // Have to do this so we maintain backwards compatability between
64
+ // react-router > 6.0.0 and >= 6.4.2.
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ type RouteObjectArrayAlias = any ;
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ type RouteMatchAlias = any ;
69
+ type CreateRoutesFromChildren = ( children : JSX . Element [ ] ) => RouteObjectArrayAlias ;
70
+ type MatchRoutes = ( routes : RouteObjectArrayAlias , location : Location ) => RouteMatchAlias [ ] | null ;
50
71
51
72
let activeTransaction : Transaction | undefined ;
52
73
@@ -106,7 +127,7 @@ function getNormalizedName(
106
127
return [ location . pathname , 'url' ] ;
107
128
}
108
129
109
- const branches = matchRoutes ( routes , location ) ;
130
+ const branches = matchRoutes ( routes , location ) as unknown as RouteMatch [ ] ;
110
131
111
132
let pathBuilder = '' ;
112
133
if ( branches ) {
@@ -209,7 +230,7 @@ export function withSentryReactRouterV6Routing<P extends Record<string, any>, R
209
230
_useEffect ( ( ) => {
210
231
// Performance concern:
211
232
// This is repeated when <Routes /> is rendered.
212
- routes = _createRoutesFromChildren ( props . children ) ;
233
+ routes = _createRoutesFromChildren ( props . children ) as RouteObject [ ] ;
213
234
isBaseLocation = true ;
214
235
215
236
updatePageloadTransaction ( location , routes ) ;
0 commit comments