Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 映射路由器属性数组时要指定什么类型?_Reactjs_Typescript_React Tsx - Fatal编程技术网

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[]=[