diff --git a/src/components/getRoute.js b/src/components/getRoute.js index 231b713d1a354dd31bc5807d42740b9455b7230e..c42700621dfd48468ede57511c41dfa1fb418a61 100644 --- a/src/components/getRoute.js +++ b/src/components/getRoute.js @@ -1,17 +1,21 @@ window.hubl.getRoute = (type, returnFirst = false) => { - let availables = window.hubl.components.filter(c=>c.type==type||c.uniq==type); - availables.map(c => { - if(c.extensions) { - c.extensions.forEach(e => availables.push(e.type)); + let availables = window.hubl.components.filter(c => c.type == type || c.uniq == type); + window.hubl.components.forEach(c => { + if (c.extensions) { + c.extensions.forEach(e => { + if (e.type == type || e.uniq == type) { + availables.push(e.type); + } + }); } }); - if(availables.length > 1) { - if(returnFirst) { + if (availables.length > 1) { + if (returnFirst) { return availables[0].route; } else { - return availables[availables.length-1].route; + return availables[availables.length - 1].route; } - } else if(availables.length < 1) { + } else if (availables.length < 1) { console.error(`No component found for route ${type}`); } else { return availables[0].route; diff --git a/src/hubl-router.pug b/src/hubl-router.pug index 18bf1d429672334868f9a295e3d02a1e0ea5ba68..8e1bf957ae6bed47c0c7be6d3435c347d8e8b03e 100644 --- a/src/hubl-router.pug +++ b/src/hubl-router.pug @@ -11,19 +11,23 @@ - let routes = new Set(); const getRoute = (type, returnFirst = false) => { - let availables = components.filter(c=>c.type==type||c.uniq==type); - availables.map(c => { - if(c.extensions) { - c.extensions.forEach(e => availables.push(e.type)); + let availables = components.filter(c => c.type == type || c.uniq == type); + components.forEach(c => { + if (c.extensions) { + c.extensions.forEach(e => { + if (e.type == type || e.uniq == type) { + availables.push(e.type); + } + }); } }); - if(availables.length > 1) { - if(returnFirst) { + if (availables.length > 1) { + if (returnFirst) { return availables[0].route; } else { - return availables[availables.length-1].route; + return availables[availables.length - 1].route; } - } else if(availables.length < 1) { + } else if (availables.length < 1) { console.error(`No component found for route ${type}`); } else { return availables[0].route;