Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
rafael-zilberman opened this issue Oct 14, 2022 · 1 comment · Fixed by #5971
Closed
3 tasks done

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

rafael-zilberman opened this issue Oct 14, 2022 · 1 comment · Fixed by #5971

Comments

@rafael-zilberman
Copy link

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

@rafael-zilberman
Copy link
Author

rafael-zilberman commented Oct 14, 2022

Workaround for now is to remove the root paths and duplicate the wildcard children:

const routes = [
    {
-       path: "/",
        element: <NavBarLayout/>,
        children: [
            {
                path: "tests",
                children: [
                  {index: true, element: <TestComponent />},
+                 {path: ":testId",element: <OtherTestComponent />},
                  {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/>},
        ],
    },
];

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

Successfully merging a pull request may close this issue.

2 participants