Last active
December 16, 2016 20:18
-
-
Save matt-hensley/6a711da7150f7e9cf153b28d0907f532 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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