Reload current page in Aurelia

前端 未结 4 1682
醉酒成梦
醉酒成梦 2021-01-03 22:35

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,

4条回答
  •  心在旅途
    2021-01-03 23:34

    Here is a simple solution to refresh the page: in aurelia-history-browser.js, added a check in updateHash() and if the new _href is equal to the old then reload the page from the cache (not the server).

    Then, to refresh the page you just need to use the existing options:

    router.navigateToRoute('watch', {}, { replace: true, trigger: true });
    

    The updated code is copied below:

    function updateHash(location, fragment, replace) {
        if (replace) {
          var _href = location.href.replace(/(javascript:|#).*$/, '') + '#' + fragment;
          if (_href == location.href)
            location.reload(false);
          else
            location.replace(_href);
        } else {
          location.hash = '#' + fragment;
        }
      }
    

提交回复
热议问题