-1

I'm using AngularJS not to build SPA but just for certain features in the system. I'm having a trouble to find out why Angular is preventing page from being refreshed after it get's there or how to disable/workaround it.

So I have simple menu:

<ul>
    <li><a href="/admin">Homepage</a></li>
    <li><a href="/admin/profile">Profile</a></li>
</ul>

And when I'm already on the http://example.com/admin page and I'm clicking in first link (/admin) then nothing happens.

I could detect if a certain a element has a href and then use window.location but unfortunately I'm using AJAX in some other parts of the system so that won't fit.

Please advise.

2 Answers2

3

You're working with a Single Page Application. The router takes care of navigating between different application routes, but the browser never fetches an entirely new page.

When you click on a link for a page that you're already on, there is no where to navigate to.

EDIT: You could write a directive that will detect clicks on anchor tags, and if the route is the same, it could trigger a page refresh. That will give you the behaviour you're looking for. However, I struggle to where this would be desirable.

EDIT 2: This is what stops your navigation: https://github.com/angular/angular.js/blob/v1.5.x/src/ng/location.js#L889.

As far as I can see, there is nothing you can do to disable that behaviour, or if there is, it will be an uglier and more fragile solution that creating your own directive that will trigger a page refresh.

Merott
  • 7,189
  • 6
  • 40
  • 52
  • Thing is I'm not :) as I already wrote it - I just have system that and I want to use angular for certain features - for example build-in floating Q&A tool. So yes, there is a place where to navigate. – Tomasz Ozga May 11 '16 at 13:44
  • Yeah, I think that could be an option but I would rather first try to disable this behavior from Angular side rather than write such a directive as this can be a problem in future. – Tomasz Ozga May 11 '16 at 13:46
  • Are you using `$route` (ngRoute)? – Merott May 11 '16 at 13:50
  • No, I do not use `ngRoute` - I don't need it. – Tomasz Ozga May 11 '16 at 13:52
0

you need to be using ng-href and http://plnkr.co/edit/stdkjN?p=preview

  • Yeah, maybe, however I doubt. I'm not really able to rewrite whole system in order to user AngularJS as a library for certain parts. – Tomasz Ozga May 11 '16 at 13:41