Created
July 28, 2015 11:46
-
-
Save codepunkt/1bd6cb4a560dc16da4d5 to your computer and use it in GitHub Desktop.
wip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onlyUnique(value, index, self) { | |
return self.indexOf(value) === index; | |
} | |
function findMatchingRoutes(routes, urlPath, ancestors) { | |
var result = []; | |
ancestors = ancestors || []; | |
routes.forEach(function (route) { | |
var path = _URLUtils.stripLeadingSlashes(route.path); | |
var added = false; | |
console.log(urlPath, _URLUtils.reduceDoubleSlash((ancestors.length ? ancestors[ancestors.length - 1] : '') + '/' + path)); | |
if (route.path && urlPath === _URLUtils.reduceDoubleSlash((ancestors.length ? ancestors[ancestors.length - 1] : '') + '/' + path)) { | |
result.push(_URLUtils.reduceDoubleSlash((ancestors.length ? ancestors[ancestors.length - 1] : '') + '/' + path)); | |
added = true; | |
if (ancestors.length) { | |
result = result.concat(ancestors); | |
} | |
} | |
if (route.childRoutes) { | |
ancestors.push(_URLUtils.reduceDoubleSlash((ancestors.length ? ancestors[ancestors.length - 1] : '') + '/' + path)); | |
result = result.concat(route.path && added | |
? findMatchingRoutes(route.childRoutes, urlPath, ancestors) | |
: findMatchingRoutes(route.childRoutes, urlPath)); | |
} | |
}); | |
return result.filter(onlyUnique); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment