Page errors in route modules with subroutes: router-view is mandatory

Hi all.

We have a route module with subroutes (like the App class, it declares the configureRouter method). This has worked fine for months, but now we need to add a user profile validation that blocks that module, showing a “403 Forbidden” error message of sorts instead of the actual page.

We typically use a PageError component that renders the error message and hide all other page elements behind a <template if.bind="!pageError"> element, but if we do that in this route’s view, Aurelia throws an error that says: “There was no router-view found in the view for ./service/service-panel.”

For the time being I’m using show.bind instead of if.bind to hide the router-view, but that still instantiates the subroutes, which might do things that shouldn’t be done in their activate / attached / detached methods.

We don’t want to replicate the user profile validation on every subroute module. Instead, it would be much better if Aurelia simply did not render subroutes if no router-view is found.

Does anyone have suggestions as to how to implement this in a safe and simple way, or would it be necessary to patch the framework?


Have you tried navigationStrategy to dynamically switch moduleId based on user’s permission ?

Oh, yeah, we actually use that API for something pretty similar, but I forgot about it. I’ll give it a try on Monday. Thanks :slight_smile: