Skip to content

Commit d678e92

Browse files
committed
make sure pop and push works
1 parent f41e609 commit d678e92

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

packages/react/src/reactrouter.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ function reactRouterInstrumentation(
7676

7777
if (startTransactionOnLocationChange && history.listen) {
7878
history.listen((location, action) => {
79-
// console.log(location, action);
80-
if (action && action === 'PUSH') {
79+
if (action && (action === 'PUSH' || action === 'POP')) {
8180
if (activeTransaction) {
8281
activeTransaction.finish();
8382
}
@@ -131,11 +130,9 @@ function computeRootMatch(pathname: string): Match {
131130
return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
132131
}
133132

134-
export const withSentryRouting = (Route: React.ElementType) => (props: any) => {
135-
// tslint:disable: no-unsafe-any
133+
export const withSentryRouting = (Route: React.ElementType) => (props: { computedMatch?: Match }) => {
136134
if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
137135
activeTransaction.setName(props.computedMatch.path);
138136
}
139137
return <Route {...props} />;
140-
// tslint:enable: no-unsafe-any
141138
};

packages/react/src/reactrouterv3.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export function reactRouterV3Instrumentation(
4141
let activeTransaction: Transaction | undefined;
4242
let prevName: string | undefined;
4343

44+
// Have to use global.location because history.location might not be defined.
4445
if (startTransactionOnPageLoad && global && global.location) {
45-
// Have to use global.location because history.location might not be defined.
4646
prevName = normalizeTransactionName(routes, global.location, match);
47+
4748
activeTransaction = startTransaction({
4849
name: prevName,
4950
op: 'pageload',
@@ -55,15 +56,14 @@ export function reactRouterV3Instrumentation(
5556

5657
if (startTransactionOnLocationChange && history.listen) {
5758
history.listen(location => {
58-
if (location.action === 'PUSH') {
59+
if (location.action === 'PUSH' || location.action === 'POP') {
5960
if (activeTransaction) {
6061
activeTransaction.finish();
6162
}
6263
const tags: Record<string, string> = { 'routing.instrumentation': 'react-router-v3' };
6364
if (prevName) {
6465
tags.from = prevName;
6566
}
66-
6767
prevName = normalizeTransactionName(routes, location, match);
6868
activeTransaction = startTransaction({
6969
name: prevName,

0 commit comments

Comments
 (0)