Skip to content

Support React Router v6 #4118

Closed
Closed
@quisido

Description

@quisido

The reactRouterV#Instrumentation is no longer supported in React Router v6. Unlike previous versions of React Router, v6 does not expose the history object.

I've attempted to solve this personally, so as to unblock myself in my projects: react-router-v6-instrumentation on NPM.

Example usage:

import { init } from '@sentry/react';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import useBrowserTracing from 'react-router-v6-instrumentation';

function App() {
  const browserTracing = useBrowserTracing();

  // Initialize Sentry with the browser tracing integration.
  useEffect(() => {
    init({
      integrations: [browserTracing],
    });
  }, [browserTracing]);

  return <>Hello world!</>;
}

render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById('root'),
);

Source code on GitHub

I hope this ticket inspires the maintainers to implement (credit? 😆) or unblocks others who are searching for solutions to this issue.

Metadata

Metadata

Assignees

No one assigned

    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