Navigating Aurelia app from outside of the app

Is it possible to use the Aurelia router from outside of the Aurelia app to trigger navigation to another route?

I have an ASP.Net Core MVC app with it’s own navigation, and an Aurelia app embedded into part of the MVC app as a mini-spa. I want to be able to use parts of the MVC navigation to navigate the mini-spa. I have tried to expose the router to the window and use that directly from my navigation, and the result is that the SPA navigates to the specified route and then navigates back to the previous route. I have consumed all the routing events and there is no error. I’ve compared the router’s Completed event for both the nav inside and nav outside (before it redirects) and the results are identical.

Any ideas?

1 Like

From the root host element of an Aurelia application, you can access the Aurelia instance via hostElement.aurelia. Then from there, you can do

hostElement.aurelia.container.get(Router).navigate(...)
hostElement.aurelia.container.get(Router).navigateToRoute(...)
2 Likes