Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally have anchor links send user to a different page, rather than load to ng-view

Tags:

angularjs

I have a view that contains an anchor link. That link has an href to another url in my site. Angular tries to load that site, using html5mode. I would rather just have default behavior for that link and send the user off to the url. How can I specify that this particular link should behave like a normal html link, not an angular route?

like image 418
Jim Geurts Avatar asked Oct 23 '12 03:10

Jim Geurts


People also ask

How do you jump to a specific section in HTML?

Method 1: Using HTML: One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.


1 Answers

AngularJS understands a few rules that will make the browser perform a full reload. The rules are documented under the 'Html link rewriting' section in the $location service documentation.

From the documentation:

In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.

  • Links that contain target element Example: <a href="/ext/link?a=b" target="_self">link</a>
  • Absolute links that go to a different domain Example: <a href="http://angularjs.org/">link</a>
  • Links starting with '/' that lead to a different base path when base is defined Example: <a href="/not-my-base/link">link</a>

Note that the last example only works if you have used the base element in the head section of your page:

<base href="/my-base/" />
like image 90
Martin Avatar answered Oct 04 '22 19:10

Martin