Gathers the navigation instructions and displays the taken routes to get to the current route.
Requires your routing to be set up with child routing to achieve multiple layers of routing.
Refreshes on Aurelia's router:navigation:complete
event.
import { NavigationInstruction } from 'aurelia-router'; | |
export class GenerateRouteUrlValueConverter { | |
/** | |
* Generates a route URL for given navigation instruction. | |
* @param instruction The instruction to generate a route url for. | |
* @param absolute Whether the route url should be absolute (https://absolute.path/route/path). | |
* If false, the URL will be relative (/relative/path). | |
*/ | |
private toView(instruction: NavigationInstruction, absolute: boolean = false): string { | |
const params = Object.assign(instruction.params); | |
// Remove the childRoute parameter, placed there by the router, from the params object as we don't need it here | |
delete params.childRoute; | |
// Generate the route URL for the given instruction | |
return instruction.router.generate(instruction.config.name, params, { absolute }); | |
} | |
} |