react路由安装使用时报错
dearweb 发布:2021-10-25 15:15:07阅读:错误提示信息
when use withRouter in your component under the typescript language,it may cause error below
TS12345: Argument of type 'typeof BILink' is not assignable to parameter of type 'ComponentType<RouterComponentProps<any, StaticContext>>'. Type 'typeof BILink' provides no match for singnature '{props: RouteComponentProps<any, StaticContext} & {children?: ReactNode;}, context?: any): ReactElement<any>'
问题解决方案
interface props { // your props here } interface states { // attributes needed in your component here } export class YourComponent extends React.Component<props, states>{ // constructor in required here contructor (props: any){ super(props); ... } } export default withRouter(YourComponent) // another way to solve the problem type PathParamsType { // type whatever you expect in the this.props.match.params.* } type PropsType = RouteComponentProps<PathParamsType> & { // your props here } export class YourComponent extends React.Component<PropsType>{ ... } export default withRouter(YourComponent)
小礼物走一波,支持作者
赏还没有人赞赏,支持一波吧