【发布时间】:2026-02-17 02:30:01
【问题描述】:
我正在使用react-router-dom 并从这样的数组动态生成我的路线
路线数据
const routes = [
{
path: '/',
exact: true,
component: () => <MyComponent />
}
}
路线生成
{routes.map((route, index) => {
return <Route
key={index}
path={route.path}
exact={route.exact}
component={route.component}
/>
})}
渲染道具 我发现了我可以定义的 render() 道具,但即便如此,我该怎么做,因为组件在变量中
const props = this.props;
{routes.map((route, index) => {
return <Route
key={index}
path={route.path}
exact={route.exact}
render={(props) => <??? {...props} />
/>
})}
如何在路由生成过程中传递 this.props?
【问题讨论】:
标签: javascript reactjs react-router react-router-dom