Skip to main content
useEffect in ReactJS
Get the current route in React

To get the current route, use the useLocation() hook.

if still getting Error: useRoutes() may be used only in the context of a component.

use  <BrowserRouter>  in index.php file rather than app.js

You should have a <BrowserRouter>  higher up in the tree. Note that higher up means that it can't be in the <App> itself, but at least in the component that renders it. 
As we know that index.js render app component so use <BrowserRouter> in index.php

Subscribe to React