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: docs/platforms/javascript/guides/react/features/react-router/v6.mdx
+16-21Lines changed: 16 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,8 @@ sidebar_order: 20
5
5
---
6
6
7
7
<Alertlevel="info">
8
-
- React Router v6 support is included in the `@sentry/react` package since version `7`.
8
+
- React Router v6 support is included in the `@sentry/react` package since
9
+
version `7`.
9
10
</Alert>
10
11
11
12
Update your `Sentry.browserTracingIntegration` to `Sentry.reactRouterV6BrowserTracingIntegration` and provide the required React hooks and router functions:
@@ -17,20 +18,24 @@ Update your `Sentry.browserTracingIntegration` to `Sentry.reactRouterV6BrowserTr
17
18
<Alertlevel="warning">
18
19
19
20
To ensure proper routing instrumentation, initialize Sentry by calling `Sentry.init`**before**:
21
+
20
22
- Wrapping your `<Routes />` component
21
23
- Using `useRoutes`
22
-
- Using `createBrowserRouterV6`
24
+
- Using `wrapCreateBrowserRouterV6` or `wrapCreateMemoryRouterV6`
23
25
24
26
</Alert>
25
27
26
-
### Usage with `createBrowserRouter`
28
+
### Usage with `createBrowserRouter` or `createMemoryRouter`
27
29
28
-
<Alertlevel="info">
29
-
Available in `@sentry/react` version `7.21.0` and above.
30
-
</Alert>
30
+
If you choose to create your router instance with [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router) or [`createMemoryRouter`](https://reactrouter.com/en/main/routers/create-memory-router), you can use `Sentry.wrapCreateBrowserRouterV6` or `Sentry.wrapCreateMemoryRouterV6` to wrap it with the instrumentation:
31
+
32
+
<Alertlevel="warning"title="Note">
31
33
32
-
If you choose to create your router instance with [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router) from the `react-router-dom` package, you can use `Sentry.wrapCreateBrowserRouterV6` to wrap it with the instrumentation:
34
+
`wrapCreateMemoryRouterV6` was introduced in SDK version 8.50.0. Prior to that version, we suggested using `wrapCreateBrowserRouterV6` with `createMemoryRouter`. If you are currently using `wrapCreateBrowserRouterV6` to wrap `createMemoryRouter`, it is recommended that you use `wrapCreateMemoryRouterV6` instead.
33
35
36
+
You can instrument [`createHashRouter`](https://reactrouter.com/en/main/routers/create-hash-router) using the `wrapCreateBrowserRouterV6` function.
You can instrument [`createMemoryRouter`](https://reactrouter.com/en/main/routers/create-memory-router) and [`createHashRouter`](https://reactrouter.com/en/main/routers/create-hash-router) using the `wrapCreateBrowserRouterV6` function.
72
-
73
-
</Alert>
74
-
75
-
76
74
### Usage With `<Routes />` Component
77
75
78
76
If you're using the `<Routes />` component to define your routes, wrap [`Routes`](https://reactrouter.com/en/main/components/routes) using `Sentry.withSentryReactRouterV6Routing`. This creates a higher order component, which will enable Sentry to reach your router context. You can also use `Sentry.withSentryReactRouterV6Routing` for `Routes` inside `BrowserRouter`. `MemoryRouter`, and `HashRouter` components:
79
77
80
-
81
78
```javascript {3-11, 18-24, 29, 33-35}
82
79
importReactfrom"react";
83
80
importReactDOMfrom"react-dom";
@@ -123,7 +120,7 @@ This is only needed at the top level of your app, rather than how v4/v5 required
123
120
### Usage With `useRoutes` Hook
124
121
125
122
<Alertlevel="info">
126
-
Available in `@sentry/react` version `7.12.1` and above.
123
+
Available in `@sentry/react` version `7.12.1` and above.
127
124
</Alert>
128
125
129
126
If you specify your route definitions as an object to the [`useRoutes` hook](https://reactrouter.com/en/main/hooks/use-routes), use `Sentry.wrapUseRoutesV6` to create a patched `useRoutes` hook that instruments your routes with Sentry.
@@ -134,7 +131,6 @@ If you specify your route definitions as an object to the [`useRoutes` hook](htt
134
131
135
132
</Alert>
136
133
137
-
138
134
```javascript {2-10, 15-21, 26, 29-31}
139
135
importReactfrom"react";
140
136
import {
@@ -179,13 +175,13 @@ ReactDOM.render(
179
175
180
176
Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, `/teams/:teamid/user/:userid`), where applicable. This is only needed at the top level of your app, rather than how v4/v5 required wrapping every `<Route/>` you wanted parametrized.
181
177
182
-
183
178
### Custom Error Boundaries
184
179
185
180
When using `react-router`, errors thrown inside route elements will only be re-thrown in **development mode** while using [`strict mode`](https://react.dev/reference/react/StrictMode). In production, these errors won't be surfaced unless manually captured. If you **don't** have a custom error boundary in place, `react-router` will create a default one that "swallows" all errors.
186
181
187
182
<Note>
188
-
Note, that this only applies to render method and lifecycle errors since React doesn't need error boundaries to handle errors in event handlers.
183
+
Note, that this only applies to render method and lifecycle errors since React
184
+
doesn't need error boundaries to handle errors in event handlers.
189
185
</Note>
190
186
191
187
To send errors to Sentry while using a custom error boundary, use the `Sentry.captureException` method:
Copy file name to clipboardExpand all lines: docs/platforms/javascript/guides/react/features/react-router/v7.mdx
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,9 @@ sidebar_order: 10
5
5
---
6
6
7
7
<Alertlevel="info">
8
-
- React Router v7 (library mode) support is included in the `@sentry/react` package since version `8.42.0`.
9
-
- React Router v7 (framework mode) is not yet supported.
8
+
- React Router v7 (library mode) support is included in the `@sentry/react`
9
+
package since version `8.42.0`. - React Router v7 (framework mode) is not yet
10
+
supported.
10
11
</Alert>
11
12
12
13
Update your `Sentry.browserTracingIntegration` to `Sentry.reactRouterV7BrowserTracingIntegration` and provide the required React hooks and router functions:
@@ -18,16 +19,24 @@ Update your `Sentry.browserTracingIntegration` to `Sentry.reactRouterV7BrowserTr
18
19
<Alertlevel="warning">
19
20
20
21
To ensure proper routing instrumentation, initialize Sentry by calling `Sentry.init`**before**:
22
+
21
23
- Wrapping your `<Routes />` component
22
24
- Using `useRoutes`
23
-
- Using `createBrowserRouterV7`
25
+
- Using `wrapCreateBrowserRouterV7` or `wrapCreateMemoryRouterV7`
24
26
25
27
</Alert>
26
28
27
-
### Usage with `createBrowserRouter`
29
+
### Usage with `createBrowserRouter` or `createMemoryRouter`
30
+
31
+
If you choose to create your router instance with [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router) or [`createMemoryRouter`](https://reactrouter.com/en/main/routers/create-memory-router), you can use `Sentry.wrapCreateBrowserRouterV7` or `Sentry.wrapCreateMemoryRouterV7` to wrap it with the instrumentation:
32
+
33
+
<Alertlevel="warning"title="Note">
34
+
35
+
`wrapCreateMemoryRouterV7` was introduced in SDK version 8.50.0. Prior to that version, we suggested using `wrapCreateBrowserRouterV7` with `createMemoryRouter`. If you are currently using `wrapCreateBrowserRouterV7` to wrap `createMemoryRouter`, it is recommended that you use `wrapCreateMemoryRouterV7` instead.
28
36
29
-
If you choose to create your router instance with [`createBrowserRouter`](https://reactrouter.com/en/main/routers/create-browser-router)from the `react-router` package, you can use `Sentry.wrapCreateBrowserRouterV7`to wrap it with the instrumentation:
37
+
You can instrument [`createHashRouter`](https://reactrouter.com/en/main/routers/create-hash-router)using the `wrapCreateBrowserRouterV7`function.
You can instrument [`createMemoryRouter`](https://reactrouter.com/en/main/routers/create-memory-router) and [`createHashRouter`](https://reactrouter.com/en/main/routers/create-hash-router) using the `wrapCreateBrowserRouter` function.
69
-
70
-
</Alert>
71
-
72
-
73
75
### Usage With `<Routes />` Component
74
76
75
77
If you're using the `<Routes />` component to define your routes, wrap [`Routes`](https://reactrouter.com/en/main/components/routes) using `Sentry.withSentryReactRouterV7Routing`. This creates a higher order component, which will enable Sentry to reach your router context. You can also use `Sentry.withSentryReactRouterV7Routing` for `Routes` inside `BrowserRouter`. `MemoryRouter`, and `HashRouter` components:
76
78
77
-
78
79
```javascript {3-11, 18-24, 29, 33-35}
79
80
importReactfrom"react";
80
81
importReactDOMfrom"react-dom";
@@ -127,7 +128,6 @@ If you specify your route definitions as an object to the [`useRoutes` hook](htt
127
128
128
129
</Alert>
129
130
130
-
131
131
```javascript {2-10, 15-21, 26, 29-31}
132
132
importReactfrom"react";
133
133
import {
@@ -172,18 +172,17 @@ ReactDOM.render(
172
172
173
173
Now, Sentry should generate `pageload`/`navigation` transactions with parameterized transaction names (for example, `/teams/:teamid/user/:userid`), where applicable. This is only needed at the top level of your app, rather than how v4/v5 required wrapping every `<Route/>` you wanted parametrized.
174
174
175
-
176
175
### Custom Error Boundaries
177
176
178
177
When using `react-router`, errors thrown inside route elements will only be re-thrown in **development mode** while using [`strict mode`](https://react.dev/reference/react/StrictMode). In production, these errors won't be surfaced unless manually captured. If you **don't** have a custom error boundary in place, `react-router` will create a default one that "swallows" all errors.
179
178
180
179
<Note>
181
-
Note, that this only applies to render method and lifecycle errors since React doesn't need error boundaries to handle errors in event handlers.
180
+
Note, that this only applies to render method and lifecycle errors since React
181
+
doesn't need error boundaries to handle errors in event handlers.
182
182
</Note>
183
183
184
184
To send errors to Sentry while using a custom error boundary, use the `Sentry.captureException` method:
0 commit comments