### withRouter在typescript下的使用 ###
利用react-router4官方提供的的withRouter进行路由跳转,在项目引入:
import { Route, withRouter } from 'react-router'
然后利用withRouter包裹组件:
class SingerBase extends Component<singerProps, singerState>{
...
}
const Singer = withRouter(SingerBase as any);
export default Singer
接口singerProps中应该加上接口属性history,类型这里设置为any,更严格的,通过查找react-router对应的声明文件d.ts(node_module/@types/react-router/inde.d.ts文件)中可以找到history对应的类型如下:
export interface RouterProps {
history: H.History;
}
This file has been truncated. show original