Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Created July 28, 2015 11:46
Show Gist options
  • Save codepunkt/1bd6cb4a560dc16da4d5 to your computer and use it in GitHub Desktop.
Save codepunkt/1bd6cb4a560dc16da4d5 to your computer and use it in GitHub Desktop.
wip
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