Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS won't refresh the page if the link that is clicked is with the same URL as the current page

Tags:

angularjs

I noticed this on two of my projects where I'm using AngularJS, so I'm assuming it's an issue with AngularJS.

Let's say I have a button on the menu that says "Register" and takes me to /account/register page. But, if I'm on the /account/register page, clicking the button won't refresh the page. It's like the button is disabled. This is always happening when the link I want to click has the same URL as the current page I'm on. The URLs are simple <a href="something1/something2">Link</a>. How can I remove this behavior?

like image 243
Andrej Avatar asked Jul 03 '14 09:07

Andrej


3 Answers

Had the same problem with angular, adding target="_parent" attribute to the link made it work.

like image 180
Pavel M. Avatar answered Sep 22 '22 12:09

Pavel M.


For who didn't understand, I have recorded my screen to display this issue. Basically, there are somethings wrong of Angular.

Zone not loaded

  1. If we place the navigation outside of the ng-app.
  2. The app has already loaded.
  3. Then we click again to this navigation.
  4. The app will disappear with no reason.

I fixed it by adding target="_parent" or target="_self" attribute to the anchor tag as answered above.

Check more on Angular docs

like image 24
trungk18 Avatar answered Sep 19 '22 12:09

trungk18


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

AngularJs: Reload page

like image 25
Saurav Avatar answered Sep 22 '22 12:09

Saurav