Skip to content

react-router integration doesn't support root and wildcard brances  #5965

@rafael-zilberman

Description

@rafael-zilberman

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

SDK Version

7.15.0

Framework Version

17.0.2

Link to Sentry event

No response

Steps to Reproduce

  1. Configure react router v6 integration in BrowserTracing intergation:
Sentry.init({
    dsn: process.env.REACT_APP_SENTRY_DSN,
    integrations: [
        new BrowserTracing({
            routingInstrumentation: Sentry.reactRouterV6Instrumentation(
                useEffect,
                useLocation,
                useNavigationType,
                createRoutesFromChildren,
                matchRoutes,
            ),
        }),
        new ExtraErrorDataIntegration(),
        new OfflineIntegration(),
        postHogIntegration
    ],
    tracesSampleRate: 1.0,
});
2. Wrap react-router `useRoutes`:
```js
const useSentryRoutes = Sentry.wrapUseRoutes(useRoutes);
const App = () => {
    return useSentryRoutes(routes);
}
  1. Use the following routes example:
const routes = [
    {
        path: "/",
        element: <NavBarLayout/>,
        children: [
            {
                path: "tests",
                children: [
                  {index: true, element: <TestComponent />},
                  {path: ":testId/*",element: <OtherTestComponent />},
                ]
              },
            {path: "/", element: <Navigate to="/home"/>},
            {path: "*", element: <Navigate to="/404" replace/>},
        ],
    },
    {
        path: "/",
        element: <MainLayout/>,
        children: [
            {path: "404", element: <Error />},
            {path: "*", element: <Navigate to="/404" replace/>},
        ],
    },
];

Expected Result

Traces with the url template to be /tests/:testId when I navigate to /tests/123 and /tests when I navigate to /tests

Actual Result

Traces with the url template of /:testId/* when I navigate to /tests/123 and //tests when I navigate to /tests

Metadata

Metadata

Assignees

Labels

Package: reactIssues related to the Sentry React SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions