Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
toArray: function (children) {
if (isNullOrUndef(children)) {
return [];
}
// We need to flatten arrays here,
// because React does it also and application level code might depend on that behavior
if (isArray(children)) {
const result = [];
flatten(children, result);
return result;
}
return ARR.concat(children);
}
};
const node: IPlainRouteConfig = {} as IPlainRouteConfig;
for (const key in routeConfigNode) {
node[key] = routeConfigNode[key];
}
node.children = [];
// handle index route config
if (node.indexRoute) {
node.children.push(handleIndexRoute(node.indexRoute));
delete node.indexRoute;
}
// handle child routes config
if (node.childRoutes) {
const nodes: IPlainRouteConfig[] = isArray(node.childRoutes)
? node.childRoutes
: [node.childRoutes];
node.children.push(...handleChildRoutes(nodes));
delete node.childRoutes;
}
// cleanup to match native rendered result
if (node.children.length === 1) {
node.children = node.children[0];
}
if (
(isArray(node.children) && node.children.length === 0) ||
(!isArray(node.children) && Object.keys(node.children).length === 0)
) {
delete node.children;
}
// handle child routes config
if (node.childRoutes) {
const nodes: IPlainRouteConfig[] = isArray(node.childRoutes)
? node.childRoutes
: [node.childRoutes];
node.children.push(...handleChildRoutes(nodes));
delete node.childRoutes;
}
// cleanup to match native rendered result
if (node.children.length === 1) {
node.children = node.children[0];
}
if (
(isArray(node.children) && node.children.length === 0) ||
(!isArray(node.children) && Object.keys(node.children).length === 0)
) {
delete node.children;
}
return createElement(Route, node);
}
function extractMatchFromChildren(children, route, location) {
let match;
let _child: any;
if (isArray(children)) {
for (let i = 0; i < children.length; ++i) {
_child = children[i];
if (isArray(_child)) {
const nestedMatch = extractMatchFromChildren(_child, route, location);
match = nestedMatch.match;
_child = nestedMatch._child;
} else {
match = getMatch(_child.props, route, location);
}
if (match) {
break;
}
}
} else {