angularjs - refresh when clicked on link with actual url

后端 未结 10 1246
深忆病人
深忆病人 2020-12-02 10:13

I use routeProvider to define controlers and templates for my urls.

When I click on the link, which has the same url as is the actual location, nothing happens. I w

10条回答
  •  有刺的猬
    2020-12-02 10:23

    In my case if the url is same, nothing worked including $route.reload(), $location.path(), $state.transitonTo() etc.

    So my approach was Using Dummy Page as follows,

    if( oldLocation === newLocation ) {
       // nothing worked ------------
       // window.location.reload(); it refresh the whole page
       // $route.reload();
       // $state.go($state.$current, null, { reload: true });
       // $state.transitionTo($state.current, $stateParams, {reload:true, inherit: false, notify: false } );
       // except this one
       $location.path('/dummy'); 
       $location.path($location.path());
       $scope.$apply(); 
    }
    

    You need to make '/dummy' module somewhere, the module doesn't do anything, it only change url so that next $location.path() can be applied. Don't miss $scope.$apply()

提交回复
热议问题