【发布时间】:2016-12-16 17:12:49
【问题描述】:
我有一个 React Router,其路由如下:
<Router history={history}>
<Route path='/' component={App} />
<Route path='/:fileType/:fileId' component={App} />
</Router>
这会将道具放入我的App,如下所示:
{
fileType: 'whatever',
fileId: 'ABC5734'
}
但是,我已经设计了我的组件,因此它需要这种格式:
{
file: {
type: 'whatever',
id: 'ABC5734'
}
}
因此,我想在将路径道具发送到组件之前对其进行转换。像这样的:
<Router history={history}>
<Route path='/' component={App} />
<Route
path='/:fileType/:fileId'
component={(props) => <App file={{type: props.fileType, id: props.fileId}} />} />
</Router>
这可能吗?
【问题讨论】:
标签: javascript reactjs react-router router