0

Occasionally my AngularJS app refreshes when clicking a link that takes you somewhere within the site. There doesn't appear to be any consistency with this, sometimes it's with href="/foo" and other times with ng-href="/foo/{{bar}}"

I seem to be able to reproduce this when I click between links in the navigation a bit too quickly and I get a full app refresh.

I would really like to avoid replacing all my hrefs across the site with ng-click that triggers $location.path('foo'); type functions if possible...

Anyone else encountered this issue? I'm using AngularJS 1.4.2

Thanks!

LT86
  • 635
  • 2
  • 15
  • 29
  • 1
    Can you try prefixing URL with a # to make angular router work instead of reloading the page? And are you using html5mode for url? – Arun Ghosh Jul 08 '16 at 10:32
  • In addition to Arun's comment, I'll recommend using ui-router – Ladmerc Jul 08 '16 at 10:33
  • Prefixing with # works a treat - strange as I tried this last week but must have made a mistake somewhere. Yes - html5mode true. Thank you @ArunGhosh :) – LT86 Jul 08 '16 at 10:40
  • @Ladmerc Are there a huge amount of benefits switching to ui-router? I'm 12 months into this project and it might be a mammoth task to try implementing this at this stage... – LT86 Jul 08 '16 at 10:40
  • Yeah there are, most especially if you're using angular < 1.5 – Ladmerc Jul 08 '16 at 10:46
  • Ok thanks, will do some research. We've been discussing an upgrade to 1.5 in the near future as well. – LT86 Jul 08 '16 at 10:50

1 Answers1

0

Please include some code examples where this is occurring.

Replacing all of your ng-href tags with ng-click will probably not address the problem. It is a busy task at best.

If you can find a situation where you can repeatedly reproduce this behavior -- interrogate the browser log for errors.

If you cannot reproduce this behavior -- add a decorator delegate to the $log service that sends your logs to a logging server. You will probably only want this decorator enabled in Dev and QA. If you have the infrastructure there are great benefits to doing this in Prod.

Martin
  • 15,820
  • 4
  • 47
  • 56