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
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById('root'),
);
Add new comment
Standard (Image)