@@ -44,14 +44,15 @@ export function reactRouterV3Instrumentation(
44
44
45
45
// Have to use global.location because history.location might not be defined.
46
46
if ( startTransactionOnPageLoad && global && global . location ) {
47
- prevName = normalizeTransactionName ( routes , ( global . location as unknown ) as Location , match ) ;
48
-
49
- activeTransaction = startTransaction ( {
50
- name : prevName ,
51
- op : 'pageload' ,
52
- tags : {
53
- 'routing.instrumentation' : 'react-router-v3' ,
54
- } ,
47
+ normalizeTransactionName ( routes , ( global . location as unknown ) as Location , match , ( localName : string ) => {
48
+ prevName = localName ;
49
+ activeTransaction = startTransaction ( {
50
+ name : prevName ,
51
+ op : 'pageload' ,
52
+ tags : {
53
+ 'routing.instrumentation' : 'react-router-v3' ,
54
+ } ,
55
+ } ) ;
55
56
} ) ;
56
57
}
57
58
@@ -65,11 +66,13 @@ export function reactRouterV3Instrumentation(
65
66
if ( prevName ) {
66
67
tags . from = prevName ;
67
68
}
68
- prevName = normalizeTransactionName ( routes , location , match ) ;
69
- activeTransaction = startTransaction ( {
70
- name : prevName ,
71
- op : 'navigation' ,
72
- tags,
69
+ normalizeTransactionName ( routes , location , match , ( localName : string ) => {
70
+ prevName = localName ;
71
+ activeTransaction = startTransaction ( {
72
+ name : prevName ,
73
+ op : 'navigation' ,
74
+ tags,
75
+ } ) ;
73
76
} ) ;
74
77
}
75
78
} ) ;
@@ -80,7 +83,12 @@ export function reactRouterV3Instrumentation(
80
83
/**
81
84
* Normalize transaction names using `Router.match`
82
85
*/
83
- function normalizeTransactionName ( appRoutes : Route [ ] , location : Location , match : Match ) : string {
86
+ function normalizeTransactionName (
87
+ appRoutes : Route [ ] ,
88
+ location : Location ,
89
+ match : Match ,
90
+ callback : ( pathname : string ) => void ,
91
+ ) : void {
84
92
let name = location . pathname ;
85
93
match (
86
94
{
@@ -89,19 +97,18 @@ function normalizeTransactionName(appRoutes: Route[], location: Location, match:
89
97
} ,
90
98
( error , _redirectLocation , renderProps ) => {
91
99
if ( error || ! renderProps ) {
92
- return name ;
100
+ return callback ( name ) ;
93
101
}
94
102
95
103
const routePath = getRouteStringFromRoutes ( renderProps . routes || [ ] ) ;
96
104
if ( routePath . length === 0 || routePath === '/*' ) {
97
- return name ;
105
+ return callback ( name ) ;
98
106
}
99
107
100
108
name = routePath ;
101
- return name ;
109
+ return callback ( name ) ;
102
110
} ,
103
111
) ;
104
- return name ;
105
112
}
106
113
107
114
/**
0 commit comments