[英]React router: How to render two different components on different pages?
I am building a react app. 我正在构建一个React应用。 I am using react-router-dom V4.
我正在使用react-router-dom V4。
class TodoApp extends React.Component{
render(){
return(
<Router>
<div>
<Route path='/' component={TodoComponent}></Route>
<Route path='/about' component={About}></Route>
</div>
</Router>
);
}
}
How can I render these two different components on different pages? 如何在不同页面上呈现这两个不同的组件? This is how the output looks:
这是输出的样子:
您需要在您的根目录/
路由中添加exact
属性,当前两个路由都与/about
匹配,因此两个组件都将显示:
<Route exact path="/" component={TodoComponent} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.