Javascript React Router v3-如何声明传递&;访问子路由的其他元数据
我有这样的路线:Javascript React Router v3-如何声明传递&;访问子路由的其他元数据,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我有这样的路线: <Router history={syncHistoryWithStore(browserHistory, store)}> <Route path='/' component={Widget}> <Route path='/a' component={A} /> <Route path='/b' component={B} expand /> <Route path='/c' component
<Router history={syncHistoryWithStore(browserHistory, store)}>
<Route path='/' component={Widget}>
<Route path='/a' component={A} />
<Route path='/b' component={B} expand />
<Route path='/c' component={C} />
</Route>
<Route path='*' component={FourOhFour} />
</Router>
render () {
const { children, route: { child: { expand } } } = this.props
return (
<div {...someOtherProps}>
{expand ? children : <p id="padded-thing">{children}</p>}
</div>
)
}
import { A, B, C } from './children';
import { Wrapper } from './wrapper';
const WrappedB = <Wrapper><B /></Wrapper>;
// ...
<Router history={syncHistoryWithStore(browserHistory, store)}>
<Route path='/' component={Widget}>
<Route path='/a' component={A} />
<Route path='/b' component={WrappedB} />
<Route path='/c' component={C} />
</Route>
<Route path='*' component={FourOhFour} />
</Router>
我相信这是一个已解决的问题,尽管我的策略可能已经失效
我确实看到了几个近乎重复的线程,比如,但考虑到我询问的是父路由和渲染子路由,我认为这已经足够不同了。谢谢 我想你可能有点不确定。React通常是自上而下的,没有很多相反的动作。通常,当您想要进行备份通信时,您会传入回调或其他信息 您提到您不希望对其进行包装,但我认为拥有包装器组件将是迄今为止最干净的方法 大概是这样的:
<Router history={syncHistoryWithStore(browserHistory, store)}>
<Route path='/' component={Widget}>
<Route path='/a' component={A} />
<Route path='/b' component={B} expand />
<Route path='/c' component={C} />
</Route>
<Route path='*' component={FourOhFour} />
</Router>
render () {
const { children, route: { child: { expand } } } = this.props
return (
<div {...someOtherProps}>
{expand ? children : <p id="padded-thing">{children}</p>}
</div>
)
}
import { A, B, C } from './children';
import { Wrapper } from './wrapper';
const WrappedB = <Wrapper><B /></Wrapper>;
// ...
<Router history={syncHistoryWithStore(browserHistory, store)}>
<Route path='/' component={Widget}>
<Route path='/a' component={A} />
<Route path='/b' component={WrappedB} />
<Route path='/c' component={C} />
</Route>
<Route path='*' component={FourOhFour} />
</Router>
从“/children”导入{A,B,C};
从“./Wrapper”导入{Wrapper};
常数WrappedB=;
// ...
这样,您就可以保持自上而下的方法,而不必做一些尴尬的家长看孩子然后呈现孩子不同的方法。doh!我很早就提交了我的评论,我想让我在评论中做一些片断。不管怎么说,我更新了我的原始帖子,以及我对它的实际设想,仍然是自上而下的。我想你的方法对我来说已经足够了。thx:)但是,我想找出一种方法,从
小部件中包装vs在路由级别上包装