Я создал функцию и, в зависимости от случая, я хочу вызвать ту же функцию
buildRoute(listRoutes){
return(
<Switch>
{listRoutes.map((prop, key) => {
if(prop.subMenus != null){
if(prop.path !== undefined){
return
this.routes(prop, key);
this.buildRoute(prop.subMenus);
}else{
return this.buildRoute(prop.subMenus);
}
}else{
return this.routes(prop, key);
}
})}
</Switch>
)
}
routes(prop, key){
if (prop.redirect){
return <Redirect from={prop.path} to={prop.to} key={key} />;
}else if(prop.private){
return <PrivateRoute authenticated={JSON.parse(localStorage.getItem(IS_AUTHENTICATED))} path={prop.path} component={prop.component} key={key} />;
}else{
return <Route path={prop.path} component={prop.component} key={key} />;
}
}
Но у меня есть эта ошибка: VM3056 53.chunk.js: 89036 Предупреждение: каждый ребенок вмассив или итератор должен иметь уникальную опору «key».
Проверьте метод рендеринга APP
.в Switch (в Dashboard.jsx: 84) в APP (создан WithStyles (APP)) в WithStyles (APP) (создан Route) в Route (в src / index.js: 46) в Switch (в src / index.js: 42) в Router (в src / index.js: 41) в I18следующий провайдер (в src / index.js: 40)
Мой списокRoute:
const dashboardRoutes = [
{
private: true,
path: "/private/dashboard",
sidebarName: "menu.sidebarName.dashboard",
navbarName: "header.navbarName.dashboard",
icon: Dashboard,
component: DashboardPage
},
{
private: true,
path: "/private/MENU1",
navbarName: "header.navbarName.MENU1",
component: MENU1,
sidebarName: "menu.sidebarName.MENU1",
code: "MENU1",
icon: "content_paste",
subMenus:[
{
subMenu: true,
private: true,
path: "/private/MENU1_SOUS_MENU1",
sidebarName: "menu.sidebarName.MENU1_SOUS_MENU1",
navbarName: "header.navbarName.MENU1_SOUS_MENU1",
code: "MENU1_SOUS_MENU1",
icon: "content_paste",
component: MENU1_SOUS_MENU1
},
{
subMenu: true,
private: true,
path: "/private/MENU1_SOUS_MENU2",
sidebarName: "menu.sidebarName.MENU1_SOUS_MENU2",
navbarName: "header.navbarName.MENU1_SOUS_MENU2",
code: "MENU1_SOUS_MENU2",
icon: "content_paste",
component: MENU1_SOUS_MENU2
}
]
},
{
sidebarName: "menu.sidebarName.MENU12",
code: "MENU12,
icon: "content_paste",
subMenus:[
{
subMenu: true,
private: true,
path: "/private/MENU2_SOUS_MENU1",
sidebarName: "menu.sidebarName.MENU2_SOUS_MENU1",
navbarName: "header.navbarName.MENU2_SOUS_MENU1",
code: "MENU2_SOUS_MENU1",
icon: "content_paste",
component: MENU2_SOUS_MENU1
},
{
subMenu: true,
private: true,
path: "/private/MENU2_SOUS_MENU2",
sidebarName: "menu.sidebarName.MENU2_SOUS_MENU2",
navbarName: "header.navbarName.MENU2_SOUS_MENU2",
code: "MENU2_SOUS_MENU2",
icon: "content_paste",
component: MENU2_SOUS_MENU2
}
]
},
.....
{
redirect: true,
path: "/private",
to: "/private/dashboard"
}
]