Is it possible to flatten this collections using lodash and concatenate the path strings? I tried to but can only reach second level, I want to flatten it regardless the depth as long as there's a pageRouter array inside the object
{
component: () => React.createElement('div', undefined, 'Parent Page'),
exact: true,
pageTitle: 'Parent',
path: '/parent',
pageRoute: [
{
component: () => React.createElement('div', undefined, 'Child Page'),
exact: true,
pageTitle: 'Child',
path: '/child',
pageRoute: [
{
component: () =>
React.createElement('div', undefined, 'Grandchild Page'),
exact: true,
pageTitle: 'GrandChild',
path: '/grandchild',
},
],
},
],
},
to this?
[
{
component: () => React.createElement('div', undefined, 'Parent Page'),
exact: true,
pageTitle: 'Parent',
path: '/parent',
},
{
component: () => React.createElement('div', undefined, 'Child Page'),
exact: true,
pageTitle: 'Child',
path: '/parent/child',
},
{
component: () => React.createElement('div', undefined, 'Grandchild Page'),
exact: true,
pageTitle: 'GrandChild',
path: 'parent/child/grandchild',
},
],
attempted code
const = routeList = _.flatMapDeep(publicRoutes, (x) => {
if (x.pageRoute) {
return [x, { ...x.pageRoute, path: x.path + _.head(x.pageRoute)?.path }];
} else return x;
});
flattenorflattenDeep?_.flatMapDeep(publicRoutes, (x) => { if (x.pageRoute) { return [x, { ...x.pageRoute, path: x.path + _.head(x.pageRoute)?.path }]; } else return x; })