This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
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'));
The post Fix – you should not use route or withrouter() outside a router appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
Pandu Rijal Pasa | Sciencx (2021-02-20T07:06:06+00:00) Fix – you should not use route or withrouter() outside a router. Retrieved from https://www.scien.cx/2021/02/20/fix-you-should-not-use-route-or-withrouter-outside-a-router/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.