Reactjs react路由器无法读取属性';推动';未定义的?
index.tsx的一些代码:Reactjs react路由器无法读取属性';推动';未定义的?,reactjs,typescript,react-router-dom,Reactjs,Typescript,React Router Dom,index.tsx的一些代码: ReactDOM.render( <MemoryRouter> <LocaleProvider locale={zhCn}> <App/> </LocaleProvider> </MemoryRouter>, document.getElementById('root') as HTMLElement ); 还报告错误: 错误TS2345:类型为“typeof App”的
ReactDOM.render(
<MemoryRouter>
<LocaleProvider locale={zhCn}>
<App/>
</LocaleProvider>
</MemoryRouter>,
document.getElementById('root') as HTMLElement
);
还报告错误:
错误TS2345:类型为“typeof App”的参数不能分配给类型为“ComponentType>”的参数
类型“typeof App”不可分配给类型“无状态组件>”
类型“typeof App”不提供与签名匹配的内容(props:RouteComponentProps&{children?:ReactNode;},context?:any):ReactElement | null)
有什么问题
谢谢你你在
应用程序中的道具
。tsx
需要从反应路由器
扩展路由组件道具
例如:
interface AppProps extends RouteComponentProps {
// rest of props
}
然后,您应该能够使用:
this.props.history.push("/your-route");
您能否演示如何使用“谢谢您提醒我”
接口AppProps Extended RouteComponentProps{history:any}
它仍然会报告错误。错误TS2339:类型“IntrinsicatAttributes&IntrinsicClassAttributes&Read…”上不存在属性“history”。您不需要将历史记录:任何添加到界面中-它是RouteComponentProps
的一部分。组件是如何声明的?extends React.component
组件中的第一个类型参数应该是AppProps
,即extends React.component
interface AppProps extends RouteComponentProps {
// rest of props
}
this.props.history.push("/your-route");