Reputation: 155
For some reason my Router isn't working properly. The first Route path above the Switch is working but the two below it aren't. When I try to follow that path on the browser it wont work. I've been looking for a while on the internet, so you guys are my last hope. I checked all path files and still no luck.
Thanks
heres the code
import React from 'react';
import Navbar from './Components/profileLayout/Navbar';
import Home from './Components/profileLayout/Home';
import './App.css';
import { Switch, Route, BrowserRouter as Router } from 'react-router-dom'
import SignIn from './Components/profileLayout/SignIn';
import Register from './Components/profileLayout/Register';
class App extends React.Component {
render() {
return (
<Router>
<div className="App">
<Navbar />
<Home />
<Route path='/' exact component={Home} />
<Switch>
<Route path="/register" exact component={Register} />
<Route path="/signin" exact component={SignIn} />
</Switch>
</div>
</Router>
);
}
}
export default App;
Upvotes: 3
Views: 59
Reputation: 777
Change your Route like this way. Keep all your Route
inside the Switch
and remove the <Home/>
after <NavBar/>
as it is already going to be appear once page loaded with '/' path
<Router>
<div className="App">
<Navbar />
<Switch>
<Route path='/' exact component={Home} />
<Route path="/register" exact component={Register} />
<Route path="/signin" exact component={SignIn} />
</Switch>
</div>
</Router>
Upvotes: 1
Reputation: 45
Put them all inside the switch component.
<Switch>
<Route path='/' exact component={Home} />
<Route path="/register" exact component={Register} />
<Route path="/signin" exact component={SignIn} />
</Switch>
Upvotes: 2