0

I think it's because I'm using the latest version of react and they have changed many components, since. All I want to do is navigate to another page. This is the error

I tried wrapping it it

<Routes>
              <button
                className="whatevr"
                onClick={() => {
                  navigate("../FeaturePage");
                }}
              >
                Features
              </button>
            </Routes>
  • Does https://stackoverflow.com/questions/70491774/usenavigate-may-be-used-only-in-the-context-of-a-router-component answer your question? – MrSrv7 Oct 29 '22 at 00:43

1 Answers1

0

Based on both errors regarding the use of the useNavigate and useRoutes hooks both needing to be used within a routing context, i.e. called with in a <Router> component, it seems that you are not actually doing this.

Render the app, or these specific components within a router.

Example:

const App = () => (
  <>
    <Navbar />
    <Routes>
      <Route path="/" .... />
      ... other routes ...
    </Routes>
  </>
);

Parent component rendering App.

<BrowserRouter>
  </App />
</BrowserRouter>
Drew Reese
  • 165,259
  • 14
  • 153
  • 181