Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions