【发布时间】:2017-02-26 20:56:48
【问题描述】:
假设我有两个名为 <Dashboard/> 的组件在用户登录后呈现,<Landing/> 在用户尚未登录时呈现
在reactjs中,如果我想使用相同的/路由,如果用户尚未登录,它将呈现<Landing/>,如果用户登录,它将呈现<Dashboard/>,我该怎么办?
<Landing/>是
<Route path="/" component={Landing} onEnter={appOnEnter}>
<IndexRoute component={Home}/>
... Other not-login-required routes ...
</Route>
而Dashboard 是
<Route path="/" component={Dashboard} onEnter={appOnEnter}>
<IndexRoute component={Home} />
... Other login-required routes ...
</Route>
我遇到了getComponent/getComponents,我想我可以像这样使用
<Route path="/" getComponent={(nextState, cb) => {
// do asynchronous stuff to find the components
cb(null, Course)
}} />
但this 似乎不建议使用该方法
我们不明确支持这种模式的原因是因为以这种方式连接事物是相当不典型的
那么实现我想要的最好方法是什么?
【问题讨论】:
标签: reactjs react-router