Vlad V Vlad V - 6 months ago 47
AngularJS Question

angular.js link behaviour - disable deep linking for specific URLs

I have a working Angular.js app with HTML5 mode enabled.

$location.Html5mode(true).hashbang("!");


What I want to achieve is to get some URLs or
<a>
tags to do the normal browsing behaviour instead of changing the URL in the address bar using HTML5 history API and handling it using Angular controllers.

I have this links:

<a href='/auth/facebook'>Sign in with Facebook</a>
<a href='/auth/twitter'>Sign in with Twitter</a>
<a href='/auth/...'>Sign in with ...</a>


And I want the browser to redirect the user to
/auth/...
so the user will be then redirected to an authentication service.

Is there any way I can do this?

Nik Nik
Answer

Adding target="_self" works in Angular 1.0.1:

<a target="_self" href='/auth/facebook'>Sign in with Facebook</a>

This feature is documented (https://docs.angularjs.org/guide/$location - search for '_self')

If you're curious, look at the angular source (line 5365 @ v1.0.1). The click hijacking only happens if !elm.attr('target') is true.