【发布时间】:2017-06-07 09:26:54
【问题描述】:
我目前正在使用 ReactJS 进行开发,我正在尝试了解 React Router,到目前为止它进展顺利,因为由于某种原因我的嵌套路由不会呈现。
基本上,当我导航到“/home”时,我希望 NavBar 呈现并在下方呈现欢迎消息,但由于某种原因,只呈现了 NavBar,它忘记了呈现欢迎消息。我哪里出错了?
请参阅下面的代码示例。
谢谢。
ReactDOM.render((
<Router history={hashHistory}>
<Route path="/" component={Login}/>
<Route path="/signup" component={Signup}/>
<Route path="/companyregistration" component={CompanyRegistration}/>
<Route path="/adduserdetails" component={AddUserDetails}/>
<Route component={NavBar}>
<Route path="/home" component={Welcome} />
</Route>
</Router>
), document.getElementById("app"))
编辑 - 导航栏:
export default React.createClass({
render() {
return (
<div>
<AppBar
showMenuIconButton={false}
title={<img src={"img/logo-nav.png"}/>}
iconElementRight={
<RaisedButton
onClick={signOut}
label="Sign Out"
primary={true}
style={styles.button}
icon={
<FontAwesome
className='super-crazy-colors'
name='sign-out'
style={{ color: '#B71C1C' }}
/>
}
/>
}
/>
{console.log(this.props.children)}
<div>{this.props.children}</div>
</div>
);
}
});
仍然没有渲染,但是 console.log(this.props.children) 正在向控制台返回“未定义”。
【问题讨论】:
标签: reactjs web react-router