ค้นหาเว็บไซต์

reactjs - ควรกำหนดประเภทอะไรเมื่อทำการแมปอาร์เรย์ของคุณสมบัติของ router?


ฉันสร้างอาร์เรย์ของคุณสมบัติสำหรับเส้นทาง

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>
  );
};

แต่ฉันได้รับข้อผิดพลาด:
ข้อผิดพลาด:(10, 57) TS2769: ไม่มีโอเวอร์โหลดที่ตรงกับการเรียกนี้
โอเวอร์โหลด 1 จาก 2, '(props: Readonly): Router', ให้ข้อผิดพลาดดังต่อไปนี้
คุณสมบัติ 'history' ขาดหายไปในประเภท '{ location?: Location | undefined; component?: ComponentClass, any> | FunctionComponent> | ComponentClass<...> | FunctionComponent<...> | undefined; ... 6 รายการเพิ่มเติม ...; key: number; }' แต่จำเป็นในประเภท 'Readonly'.
โอเวอร์โหลด 2 จาก 2, '(props: RouterProps, context?: any): Router', ให้ข้อผิดพลาดดังต่อไปนี้
คุณสมบัติ 'history' ขาดหายไปในประเภท '{ location?: Location | undefined; component?: ComponentClass, any> | FunctionComponent> | ComponentClass<...> | FunctionComponent<...> | undefined; ... 6 รายการเพิ่มเติม ...; key: number; }' แต่จำเป็นในประเภท 'Readonly'.