Reload current page in Aurelia

Total
19
Shares

I have an Aurelia application where the user can select the company they’re currently “working on”. Every page in the app is dependent on the currently selected company, and the user can select a new company from a drop-down menu. The drop-down is a component sitting on the nav-bar.

What I’d like is to have that component reload the current page on the change.delegate handler without restarting the app. So setting window.location.href is out of the question.

Is there a way to force the aurelia Router to reload the current route/page?

The alternative would be to use the EventAggregator to signal a company change throughout the app, but that would require either subscribing to that event on every page or having every page inherit from a base class that subscribes to that event, but these are much more involved options.


Solution

This does not answer your exact question which is how to force a reload of the current view, but have you considered adding the current company identifier to your route(s)? This will solve your problem and make your routes bookmarkable: ie: /#/company1/view1 and /#/company2/view1. When you change the company in the drop-down you call router.navigate() with the new route and the new view will be loaded/refreshed.

To answer your exact question, I tested the router.navigate options: router.navigate('myroute', {replace:true, trigger:true}) and none of them force a reload of the view if the right view is already loaded. By appending ?ramdomNumber to your route name you can force a reactivation of the view.

Leave a Reply

Your email address will not be published. Required fields are marked *