Reactjs 映射路由器属性数组时要指定什么类型?
我为一个路由创建了一个属性数组Reactjs 映射路由器属性数组时要指定什么类型?,reactjs,typescript,react-tsx,Reactjs,Typescript,React Tsx,我为一个路由创建了一个属性数组 const routes: RouteProps[] = [ { path: '/', exact: true, component: Main, }, ]; 并创建了一个单独的路由交换机组件 const Routes: FunctionComponent = (): JSX.Element => { return ( <Switch> { routes.map((prop
const routes: RouteProps[] = [
{
path: '/',
exact: true,
component: Main,
},
];
并创建了一个单独的路由交换机组件
const Routes: FunctionComponent = (): JSX.Element => {
return (
<Switch>
{
routes.map((props: RouteProps, idx: number) => <Router key={idx} {...props} />)
}
</Switch>
);
};
const路由:FunctionComponent=():JSX.Element=>{
返回(
{
routes.map((道具:RouteProps,idx:number)=>)
}
);
};
但我得到一个错误:错误:(10,57)TS2769:没有与此调用匹配的重载。
重载1/2'(道具:只读):路由器',出现以下错误。
类型“{location?:location | undefined;component?:ComponentClass,any>| FunctionComponent>| ComponentClass | FunctionComponent | undefined;…6个以上…”键:number;}中缺少属性“history”,但类型“Readonly”中需要此属性。
重载2/2'(道具:RouterProps,上下文?:any):Router'出现以下错误。
类型“{location?:location | undefined;component?:ComponentClass,any>| FunctionComponent>| ComponentClass | FunctionComponent | undefined;…6个以上…”键:number;}中缺少属性“history”'但在类型'Readonly'中是必需的。当使用
Partial
包装您的RouterProps
时会发生什么情况,如const routes:Partial[]=[