error solved

Fix – you should not use route or withrouter() outside a router


If you are getting an error of you should not use or withrouter() outside Router. This article will explain to you how to fix the issue.

This <Route /> or withRouter() belongs to react-router-dom and you are only allowed to call this inside BrowseRouter/HashRouter. So to fix this, we have to make sure that all of our components are wrapped by BrowseRouter/HashRouter.

By this, it means that the BrowseRouter/HashRouter should be located at the root of our project. Here is the example (using BrowseRouter):

import { BrowserRouter } from 'react-router-dom';

ReactDOM.render(
   <BrowserRouter>
     <App />
   </BrowserRouter>, document.getElementById('root'));

Share on social media

//