question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

beforeNavigate isn't called for ReactRouterV6

See original GitHub issue

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.11.0

Framework Version

React 17.0.2

Link to Sentry event

No response

Steps to Reproduce

  1. Setup sentry instrumentation with ReactRouterV6 according to the docs
  2. Implement some dummy function for “beforeNavigate” on BrowserTracing options
    integrations: [
      new BrowserTracing({
        routingInstrumentation: Sentry.reactRouterV6Instrumentation(
          useEffect,
          useLocation,
          useNavigationType,
          createRoutesFromChildren,
          matchRoutes,
        ),
        beforeNavigate: (ctx) => {
          console.log(ctx);
          return ctx;
        },
      }),
    ],
  1. Go into the browser and navigate across different routes

Expected Result

console would print the ctx of each navigation

Actual Result

Except pageload - initial navigation , nothing happens.

Also tried to blend into “matchRoutes” function using hoisting. Also tried to capture the event in “beforeSend” Seems like the events doesn’t go trough there. Trying to enrich the events with the route context.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AbhiPrasadcommented, Sep 28, 2022

Ah ok, was able to reproduce with https://stackblitz.com/edit/github-7tjxzc-gabqis?file=src/App.tsx. Will take a look!

1reaction
ymatusevichcommented, Sep 20, 2022

We stuck with the same issue. Hope the solution or fix will be found soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Router v6 useNavigate() doesn't navigate if ...
I just read in React Router Dom Docs v6 this solution: ... After replacing the url, manually calling navigate(0) will refresh the page...
Read more >
Navigate v6.6.1
A <Navigate> element changes the current location when it is rendered. It's a component wrapper around useNavigate , and accepts all the same...
Read more >
Navigation in React App using React Router (v6)
Guide on different ways of routing in React using the React Router. Includes nested routing, authenticated routing, accessing URL and query parameters etc....
Read more >
React Router v6
Although we bolted a few hooks onto v5 in 5.1, React Router v6 was ... Component { return ( <> {/* This route...
Read more >
React Router V6 Tutorial - Routes, Redirecting, UseNavigate ...
Hey everyone, in this video I teach you all the new version of React Router Dom. I have an old video teaching this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found