Capturing route in canLoad hook

I’m using the guidance from the Authentication and Authorization | The Aurelia 2 Docs to capture the route where the request is unauthenticated before redirecting to a login page. The canLoad method is defined in a global hook.

When a direct url for a nested route is entered, i.e. /europe/uk, the canload hook fires twice, once for each route in the tree, and all but the last call returns the associated route segment and “/*$$residue” so for the example url it would return /europe/*$$residue for the first call and /uk for the second.

Sample stackblitz: StackBlitz (I had to pop the sample out to see the path in the address bar)

This looks to be by design, but to capture the full path, I’d need to concatenate the values across calls unless the full path is available somewhere. Failing that, is there a context that’s shared across all these methods where this concatenated path could be stashed?

Those two calls are expected for a nested route. Rather than concatenating in a global, attach a small accumulator to the navigation instruction object passed through the hook, or store it in a router-scoped service keyed by a navigation id. All canLoad calls for the same navigation can then append their segment, and the redirect can read the assembled path. Keep it navigation-scoped so overlapping navigations don’t collide. If the instruction already exposes the resolved full path, prefer that over reconstructing it.