Solution to error - Error: Invariant failed: You should not use <Switch> outside a <Router>
If you are setting up routes using switch and getting the following error:
Error: Invariant failed: You should not use <Switch> outside a <Router>
Then in that case the solution is simple:
wrap your switch with BrowserRouter and import it from react-router-dom
See below for example:
If you are setting up routes using switch and getting the following error:
Error: Invariant failed: You should not use <Switch> outside a <Router>
Then in that case the solution is simple:
wrap your switch with BrowserRouter and import it from react-router-dom
See below for example:
app.js
import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import HomePage from './components/pages/home/home.component';
function App() {
return (
<div className="App">
<BrowserRouter>
<Switch>
<Route exact path='/' component={HomePage} />
</Switch>
</BrowserRouter>
</div>
);
}
export default App;
|
Really a awesome blog for the freshers. Thanks for posting the information.
ReplyDeletecontent writing course in chennai
Blockchain Training in Chennai
Ionic Training in Chennai
IoT Training in Chennai
best spoken english institute in chennai
Xamarin Training in Chennai
Node JS Training in Chennai
IELTS course in chennai
Spoken English Classes in Anna Nagar
content writing training in chennai
best content writing course in chennai
content writing classes in chennai