【发布时间】:2021-09-08 18:36:33
【问题描述】:
我正在尝试设置一个路由器,其丢失的路由将重定向到 /error ,问题是打字稿不允许我使用渲染
const App: React.FC<RouteComponentProps> = ({ history }) => {
return (
<Switch>
<Route path="/" component={ChartContainer} exact />
<Route path="/error" component={Error} />
<Route path="/" render={() => history.push("")} />
</Switch>
)
}
index.d.ts(92, 5): 预期类型来自属性'render' 这是在类型“IntrinsicAttributes & IntrinsicClassAttributes
> & Readonly & OmitNative>> & Readonly<...>'
我必须使用哪些类型?以及如何输入render?
【问题讨论】:
-
我真的不明白这条路线
<Route path="/" render={() => history.push("")} />。你想做什么? -
重定向到/在无效路由器@GiovanniEsposito 上。因为我没有特定的 404 组件
标签: reactjs typescript