0
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>
);
}
}
我有以下一段代碼。在App組件中,我想創建嵌套的路線。 '/'是根路由,/ signin是嵌套路由。不過/ signin不會呈現SignIn組件,只是'Home'div。當我在App組件中用'/'替換'/'時,'/ home/signin'會呈現'Home'div和'SignIn'組件。我在這裏做錯了什麼?React路由器4個嵌套路由沒有得到渲染