在 TypeScript 中反应路由器 - 路由器和自己的道具 [英] React router in TypeScript- both router and own props
本文介绍了在 TypeScript 中反应路由器 - 路由器和自己的道具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的组件有一些自己的道具
my component has some own props
class Props {
wizard: WizardConfig;
}
我想访问路由器历史,所以我也传递路由器道具
and I want to access router history so I also pass router props
type PropsType = Props & RouteComponentProps<{}>;
class Wizard extends React.Component<PropsType> {}
问题在于组件的使用
<Wizard wizard={someWizar} />
我收到 RouteComponentProps
道具未通过的错误,例如:类型{wizard:WizardConfig;"中缺少属性match"}'
I get errors that RouteComponentProps
props are not passed so for example:
Property 'match' is missing in type '{ wizard: WizardConfig; }'
我尝试这样做:
export default withRouter(Wizard);
但它没有帮助.
推荐答案
已修复
export default withRouter(Wizard);
到
export default withRouter<PropsType>(Wizard);
这篇关于在 TypeScript 中反应路由器 - 路由器和自己的道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文