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
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,52 @@ ReactDOM.render(
151
151
152
152
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, unlike React Router v4/v5, which required wrapping every `<Route />` you wanted parametrized.
153
153
154
+
## Static Route Manifest
155
+
156
+
<AvailableSinceversion="10.39.0" />
157
+
158
+
When using [`patchRoutesOnNavigation`](https://reactrouter.com/6.30.3/routers/create-browser-router#optspatchroutesonnavigation) to dynamically load route definitions, the full route hierarchy isn't available to Sentry until each route is navigated to. This can cause transactions to receive incomplete or wildcard names (for example, `/users/*` instead of `/users/:userId`).
159
+
160
+
To ensure accurate transaction names, you can provide a static list of route patterns via the `lazyRouteManifest` option. When provided, Sentry uses this manifest as the primary source for determining transaction names without needing to wait for route modules to load.
161
+
162
+
Make sure to keep the `lazyRouteManifest` array in sync with your route definitions: if you add, remove, or change routes in your app, update this list accordingly. Any route that doesn't match a pattern in the manifest will fall back to the default behavior, which may result in incomplete transaction names until the route is visited. You can also include non-lazy routes in the manifest for convenience or consistency.
163
+
164
+
To use `lazyRouteManifest`, you need to set `enableAsyncRouteHandlers: true` in your `reactRouterV6BrowserTracingIntegration` configuration:
165
+
166
+
```javascript {20-27}
167
+
importReactfrom"react";
168
+
import {
169
+
createRoutesFromChildren,
170
+
matchRoutes,
171
+
useLocation,
172
+
useNavigationType,
173
+
} from"react-router-dom";
174
+
175
+
import*asSentryfrom"@sentry/react";
176
+
177
+
Sentry.init({
178
+
dsn:"___PUBLIC_DSN___",
179
+
integrations: [
180
+
Sentry.reactRouterV6BrowserTracingIntegration({
181
+
useEffect:React.useEffect,
182
+
useLocation,
183
+
useNavigationType,
184
+
createRoutesFromChildren,
185
+
matchRoutes,
186
+
enableAsyncRouteHandlers:true,
187
+
lazyRouteManifest: [
188
+
"/users",
189
+
"/users/:userId",
190
+
"/users/:userId/settings",
191
+
"/dashboard",
192
+
"/dashboard/analytics",
193
+
],
194
+
}),
195
+
],
196
+
tracesSampleRate:1.0,
197
+
});
198
+
```
199
+
154
200
## Set Up a Custom Error Boundary
155
201
156
202
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).\
Apply the following setup steps based on your routing method and create a
12
12
[custom error boundary](#set-up-a-custom-error-boundary) to make sure Sentry
@@ -155,6 +155,52 @@ ReactDOM.render(
155
155
156
156
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, unlike React Router v4/v5, which required wrapping every `<Route />` you wanted parametrized.
157
157
158
+
## Static Route Manifest
159
+
160
+
<AvailableSinceversion="10.39.0" />
161
+
162
+
When using [`patchRoutesOnNavigation`](https://reactrouter.com/api/data-routers/createBrowserRouter#optspatchroutesonnavigation) to dynamically load route definitions, the full route hierarchy isn't available to Sentry until each route is navigated to. This can cause transactions to receive incomplete or wildcard names (for example, `/users/*` instead of `/users/:userId`).
163
+
164
+
To ensure accurate transaction names, you can provide a static list of route patterns via the `lazyRouteManifest` option. When provided, Sentry uses this manifest as the primary source for determining transaction names without needing to wait for route modules to load.
165
+
166
+
Make sure to keep the `lazyRouteManifest` array in sync with your route definitions: if you add, remove, or change routes in your app, update this list accordingly. Any route that doesn't match a pattern in the manifest will fall back to the default behavior, which may result in incomplete transaction names until the route is visited. You can also include non-lazy routes in the manifest for convenience or consistency.
167
+
168
+
To use `lazyRouteManifest`, you need to set `enableAsyncRouteHandlers: true` in your `reactRouterV7BrowserTracingIntegration` configuration:
169
+
170
+
```javascript {20-27}
171
+
importReactfrom"react";
172
+
import {
173
+
createRoutesFromChildren,
174
+
matchRoutes,
175
+
useLocation,
176
+
useNavigationType,
177
+
} from"react-router";
178
+
179
+
import*asSentryfrom"@sentry/react";
180
+
181
+
Sentry.init({
182
+
dsn:"___PUBLIC_DSN___",
183
+
integrations: [
184
+
Sentry.reactRouterV7BrowserTracingIntegration({
185
+
useEffect:React.useEffect,
186
+
useLocation,
187
+
useNavigationType,
188
+
createRoutesFromChildren,
189
+
matchRoutes,
190
+
enableAsyncRouteHandlers:true,
191
+
lazyRouteManifest: [
192
+
"/users",
193
+
"/users/:userId",
194
+
"/users/:userId/settings",
195
+
"/dashboard",
196
+
"/dashboard/analytics",
197
+
],
198
+
}),
199
+
],
200
+
tracesSampleRate:1.0,
201
+
});
202
+
```
203
+
158
204
## Set Up a Custom Error Boundary
159
205
160
206
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).\
0 commit comments