Skip to content

Parameterized paths not picked up when using react-router-v6 with basename #9061

@rottbers

Description

@rottbers

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

7.69.0

Framework Version

React 18

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

Hope another test case is sufficient as reproduction, it's based on the existing ones in reactrouterv6.4.test.tsx:

it('works with parameterized paths and `basename`', () => {
  const [mockStartTransaction] = createInstrumentation();
  const sentryCreateBrowserRouter = wrapCreateBrowserRouter(createMemoryRouter as CreateRouterFunction);

  const router = sentryCreateBrowserRouter(
    [
      {
        path: '/',
        element: <Navigate to="some-org-id/users/some-user-id" />,
      },
      {
        path: ':orgId',
        children: [
          {
            path: 'users',
            children: [
              {
                path: ':userId',
                element: <div>User</div>,
              },
            ],
          },
        ],
      },
    ],
    {
      initialEntries: ['/admin'],
      basename: '/admin',
    },
  );

  // @ts-expect-error router is fine
  render(<RouterProvider router={router} />);

  expect(mockStartTransaction).toHaveBeenCalledTimes(2);
  expect(mockStartTransaction).toHaveBeenLastCalledWith({
    name: '/admin/:orgId/users/:userId',
    op: 'navigation',
    origin: 'auto.navigation.react.reactrouterv6',
    tags: { 'routing.instrumentation': 'react-router-v6' },
    metadata: { source: 'route' },
  });
});

Expected Result

Expect name to contain parameter names (i.e. /admin/:orgId/users/:id)

Actual Result

Name contains the parameter values (e.g. /admin/some-org-id/users/some-user-id)

Metadata

Metadata

Assignees

Labels

Package: reactIssues related to the Sentry React SDKStale

Projects

Status

Waiting for: Community

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions