react-router-dom使用@withRouter

    在React路由中,有这样一种写法,@withReact,效果就是把路由相关的方法通过props传给它包裹的组件的props上;

    跟withRouter(component)是一个效果;

    使用@这种写法的话,需要安装一个babel-plugin-transform-decorators-legacy包 cnpm i babel-plugin-transform-decorators-legacy -S

    还需要在packag文件中的babel中配置...(待完善)

猜你喜欢

转载自www.cnblogs.com/cy-bo/p/9362558.html