AngularJS will not refresh the page if a link with the same address as the current page is clicked

I noticed this in my two projects where I use AngularJS, so I assume this is a problem with AngularJS.

Say I have a button in the menu that says “Register” and it takes me to the / account / register page. But, if I'm on the / account / register page, clicking the button will not refresh the page. It is like a button disabled. This always happens when the link I want to click has the same URL as the current page on which I am included. The URLs are simple <a href="something1/something2">Link</a> . How can I remove this behavior?

+7
angularjs
source share
6 answers

There was the same problem with angular, adding the target="_parent" attribute to the link, making it work.

+6
source share

You can check if the current url / state / hash is "/ account / register" ... if so, then use the $ route service reload method.

AngularJs: Reload Page

+1
source share

For those who did not understand, I recorded my screen to display this problem. Basically, there is something wrong with Angular.

Zone not loaded

  • If we place the navigation outside the ng application.
  • The application has already been downloaded.
  • Then we click on this navigation again.
  • The application will disappear for no reason.

I fixed this by adding the target="_parent" or target="_self" attribute to the anchor tag, as mentioned above.

More on Angular docs

+1
source share

I have not found a reasonable way to check the path inside the view, but this may work:
view:

 <a link-href="path/to/same/location">same location</a> 

directive:

 app.directive('linkHref', ['$location', '$route', function ($location, $route) { return { restrict: 'A', link: function ($scope, $element, $attrs) { $element.bind('click', function () { if ($location.$$url == $attrs.activeLink) { $route.reload(); } else { $location.path($attrs.activeLink); }); } }; }]); 
0
source share

I had the same problem, and I found that if I deleted the $ location (did not use anyways) that was specified in the factory, the problem disappeared.

0
source share
 <a target="_self" href="/xxxxxxx"></a> 

fix this problem

0
source share

All Articles