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?
You have to have one API which will return boolean to enable or disable the DeepLinking. Based on business, server has to return the response. You need to hit the API on your deep linking Activity and redirect the user to browser in case of disabled deep linking and kill your activity.
What Are Deep Links? Deep links are mobile links that operate much like hyperlinks, but instead of directing users to a web page, deep links send them to a specific screen within a mobile application.
Deep links send mobile device users directly to relevant pages in your app rather than your website. Users click on ads and go directly to your app pages. You can use deep links in many Google Ads products, including App campaigns for engagement, App dynamic remarketing, and Search, Shopping, and Display campaigns.
Deep linking is the extension or usage of attribution data. Let's go through a basic example of how it works to illuminate the tech. In the explanation previously, we talked about how a user may click a link or an ad: The attribution vendor then points the user to the appropriate app store to download the app.
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.
An alternative to Fran6co's method is to disable the 'rewriteLinks' option in the $locationProvider:
$locationProvider.html5Mode({
enabled: true,
rewriteLinks: false
});
This will accomplish exactly the same thing as calling $rootElement.off('click'), but will not interfere with other javascript that handles click events on your app's root element.
See docs, and relevant source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With