我将修复开发react js时引起的错误
//router/routes.tsx file
interface AppRoute {
path?: string;
index?: boolean;
element?: JSX.Element;
nestedRoutes?: AppRoute[];
}
export const dashboardRoutes: AppRoute[] = [
{
path: PRIVATE_ROUTE_PATHS.home,
element: <PanelLayout />,
nestedRoutes: [
{ index: true, path: PRIVATE_ROUTE_PATHS.home, element: <Dashboard /> },
{ path: PRIVATE_ROUTE_PATHS.contacts, element: <Contact /> },
{ path: PRIVATE_ROUTE_PATHS.contactDetail, element: <ContactDetail /> },
],
},
];
//mian.tsx
import { dashboardRoutes } from 'router/routes';
import useBreadcrumbs from 'use-react-router-breadcrumbs';
const breadcrumbs = useBreadcrumbs(dashboardRoutes); //error
以下错误导致最后一行代码:TS2345: Argument of type 'AppRoute[]' is not assignable to parameter of type 'BreadcrumbsRoute<string>[]'. Type 'AppRoute' has no properties in common with type 'BreadcrumbsRoute<string>'.
请帮助我修复此错误
1条答案
按热度按时间68bkxrlz1#
这非常简单,首先你需要查看你用作参数的变量的类型。
dashboardRoutes
的类型为AppRoute[]
。useBreadcrumbs
仅接受BreadcrumbsRoute<string>
作为参数。您只是传入了不正确的数据类型。