路由器中的高阶组件需要传递路由器参数

Higher order component in router needs to pass router parameters

我从 'react'

创建了以下高阶组件导入 React,{ useEffect }
export const withCall = (WrappedComponent, calllName) => {

    const HOC = () => {
        useEffect(() =>{report(calllName)}, [])
        return <WrappedComponent />
    }

    return HOC
}

这条路线:

<Route exact path={pagePath/:someId} component={withCall(ContainerComponent, 'any_call_name')} />

我正在尝试访问 ContainerComponent this.props.match.params... 只要我不在两者之间使用 HoC (<Route exact path={pagePath/:someId} component={ContainerComponent} />),我就拥有这些属性,但是当我使用它时,我无法再访问它们。 如何在保持高阶组件通用的同时将它们传递给它?

试试这个:

const HOC = (props) => {
    useEffect(() =>{report(calllName)}, [])
    return <WrappedComponent {...props} />
}