Skip to content

Commit 4580b39

Browse files
onurtemizkanlizokm
andauthored
Add documentation for React Router 6.4 support. (#5822)
Co-authored-by: Liza Mock <[email protected]>
1 parent 4bcafdc commit 4580b39

File tree

1 file changed

+46
-0
lines changed
  • src/platforms/javascript/guides/react/configuration/integrations

1 file changed

+46
-0
lines changed

src/platforms/javascript/guides/react/configuration/integrations/react-router.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,51 @@ Make sure `Sentry.reactRouterV6Instrumentation` is initialized by your `Sentry.i
3434

3535
</Alert>
3636

37+
### Usage with React Router 6.4 Data API
38+
_(Available in version 7.21.0 and above)_
39+
40+
41+
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.wrapCreateBrowserRouter` to wrap it with the instrumentation:
42+
43+
```javascript
44+
import { createBrowserRouter } from 'react-router-dom';
45+
import * as Sentry from '@sentry/react';
46+
import { BrowserTracing } from '@sentry/tracing';
47+
48+
Sentry.init({
49+
dsn: '___PUBLIC_DSN___',
50+
integrations: [
51+
new BrowserTracing({
52+
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
53+
React.useEffect,
54+
useLocation,
55+
useNavigationType,
56+
createRoutesFromChildren,
57+
matchRoutes,
58+
),
59+
}),
60+
],
61+
tracesSampleRate: 1.0,
62+
});
63+
64+
65+
const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouter(
66+
createBrowserRouter
67+
);
68+
69+
const router = sentryCreateBrowserRouter([
70+
// ...
71+
]);
72+
73+
```
74+
75+
<Alert level="warning" title="Note">
76+
77+
While [`createHashRouter`](https://reactrouter.com/en/main/routers/create-hash-router) isn't supported by Sentry yet, you can instrument [`createMemoryRouter`](https://reactrouter.com/en/main/routers/create-memory-router) using the `wrapCreateBrowserRouter` function.
78+
79+
</Alert>
80+
81+
3782
### Usage With `<Routes />` Component
3883

3984
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:
@@ -99,6 +144,7 @@ import {
99144
} from "react-router-dom";
100145
import { wrapUseRoutes } from "@sentry/react";
101146
import { useEffect } from "react";
147+
import { BrowserTracing } from "@sentry/tracing";
102148

103149
Sentry.init({
104150
dsn: "___DSN___",

0 commit comments

Comments
 (0)