import React, { Component } from 'react';
import {BrowserRouter as Router,Route,Switch} from 'react-router-dom';
import Home from './home/components/home'
class App extends Component {
render() {
return (
<div className="App">
<Router>
<Switch>
<Route path="/home" component={Home}>
</Route><!--working-->
<!--<Route path="/" component={Home}>
</Route> not working -->
</Switch>
</Router>
</div>
);
}
}
class Home extends Component{
render = () => {
return (
<div>
<div>Home</div>
<Route exact path={`${this.props.match.url}/signin`} component={SignIn}>
</Route>
</div>
);
}
}
I have the following piece of code. In the App component I want to create nested routes. '/' being the root route and /signin being the nested route. However /signin doesnt render the SignIn component, just the 'Home' div. When I replace '/' with '/home' in App component then '/home/signin' renders the 'Home' div and 'SignIn' component. What am I doing wrong here?