You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/platforms/javascript/guides/react/configuration/integrations/react-router.mdx
+60-3Lines changed: 60 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,13 +22,15 @@ _(Available in version 7 and above)_
22
22
23
23
To use React Router v6 with Sentry:
24
24
25
-
1.Initialize `Sentry.reactRouterV6Instrumentation` as your routing instrumentation and provide the functions it needs to enable performance tracing:
25
+
Initialize `Sentry.reactRouterV6Instrumentation` as your routing instrumentation and provide the functions it needs to enable performance tracing:
26
26
27
27
-`useEffect` hook from `react`
28
28
-`useLocation` and `useNavigationType` hooks from `react-router-dom`
29
29
-`createRoutesFromChildren` and `matchRoutes` functions from `react-router-dom` or `react-router` packages.
30
30
31
-
2. Wrap [`Routes`](https://reactrouter.com/docs/en/v6/api#routes-and-route) using `Sentry.withSentryReactRouterV6Routing` to create a higher order component, which will enable Sentry to reach your router context, as in the example below:
31
+
### Usage With `<Routes />` Component
32
+
33
+
If you use the `<Routes />` component from `react-router-dom` to define your routes, wrap [`Routes`](https://reactrouter.com/docs/en/v6/api#routes-and-route) using `Sentry.withSentryReactRouterV6Routing`. This creates a higher order component, which will enable Sentry to reach your router context, as in the example below:
32
34
33
35
```javascript
34
36
importReactfrom'react';
@@ -70,7 +72,62 @@ ReactDOM.render(
70
72
);
71
73
```
72
74
73
-
Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, /teams/:teamid/user/:userid), where applicable.
75
+
### Usage With `useRoutes` Hook
76
+
_(Available in version 7.12.1 and above)_
77
+
78
+
If you specify your route definitions as an object to the [`useRoutes` hook](https://reactrouter.com/en/main/hooks/use-routes), use `Sentry.wrapUseRoutes` to create a patched `useRoutes` hook that instruments your routes with Sentry.
79
+
80
+
<Alertlevel="warning">
81
+
82
+
`wrapUseRoutes` should be called outside of a React component, as in the example below. It's also recommended that you assign the wrapped hook to a variable name starting with `use`, as per the [React documentation](https://reactjs.org/docs/hooks-custom.html#extracting-a-custom-hook).
Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, `/teams/:teamid/user/:userid`), where applicable.
0 commit comments