Skip to content

Crashing randomly on dev - useNavigate() may be used only in the context of a <Router> component #307

@goldylucks

Description

@goldylucks

I couldn't pin point the culprit, but sometimes I get these errors on development:

utils.ts:781 Uncaught Error: useNavigate() may be used only in the context of a <Router> component.
    at invariant (utils.ts:781:11)
    at useNavigate (hooks.tsx:158:3)
    at LinkContainer2 (LinkContainer.js:48:38)

The LinkContainer component is of course under a Router, and it works in production, but lately started happening locally 🤷‍♀️

Any ideas?

Activity

kyletsang

kyletsang commented on Jan 2, 2023

@kyletsang
Member

Did this start happening with a recent update to react router? Can you post this into the react router project along with a reproducible demo?

goldylucks

goldylucks commented on Jan 2, 2023

@goldylucks
Author

Maybe, I'm not sure, but, in the same component the crashes with react-router-bootstrap, there's a non crashing use of both Link and useNavigate directly from react-router-dom, so I don't think it's an issue on their end.

Thoughts?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kyletsang@goldylucks

        Issue actions

          Crashing randomly on dev - useNavigate() may be used only in the context of a <Router> component · Issue #307 · react-bootstrap/react-router-bootstrap