嵌套路由中的组件在this.props.children中呈现自身

时间:2016-01-23 18:01:29

标签: react-router

我正在尝试使用以下路由配置显示嵌套在父视图中的表单:

const routes = (
  <Router history={history}>
    <Route path='/' component={App}>
      <IndexRoute component={Landing}/>
      <Route path='applications' component={Applications}>
        <Route path='/new' component={ApplicationForm}/>
      </Route>
    </Route>
  </Router>
);

访问/applications时,我会渲染我的Applications组件

class Applications extends Component {
  renderContent () {
    return (
      <div className="dashboard">
        {this.props.children}
      </div>
    );
  }

  render () {
    return (
      <DashboardLayout
        content={this.renderContent()}
        {...this.props}/>
    );
  };
}

但出于某种原因,Applications组件也会呈现为this.props.children,但没有初始渲染的道具

0 个答案:

没有答案