Skip to content

Instantly share code, notes, and snippets.

@matt-hensley
Last active December 16, 2016 20:18
Show Gist options
  • Save matt-hensley/6a711da7150f7e9cf153b28d0907f532 to your computer and use it in GitHub Desktop.
Save matt-hensley/6a711da7150f7e9cf153b28d0907f532 to your computer and use it in GitHub Desktop.
function reverse_route(ctx) {
var paths = [];
var router = ctx;
var params = ctx.params || {};
paths.unshift(router.route.path);
while (!router.isRoot && router.$parent) {
router = router.$parent;
Object.assign(params, router.params);
if (router) paths.unshift(router.route.path);
}
var path = paths.reduce((ps, p) => ps + p.replace('/:__child_path__(.*)?', ''), '')
.replace(new RegExp('\/\/', 'g'), '/');
return { path, params };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment