angular.js 链接行为 - 禁用特定 URL 的深层链接 [英] angular.js link behaviour - disable deep linking for specific URLs
问题描述
我有一个启用了 HTML5 模式的 Angular.js 应用程序.
I have a working Angular.js app with HTML5 mode enabled.
$location.Html5mode(true).hashbang("!");
我想要实现的是获取一些 URL 或 标签来执行正常的浏览行为,而不是使用 HTML5 历史 API 更改地址栏中的 URL 并使用 Angular 处理它控制器.
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.
我有这个链接:
<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>
而且我希望浏览器将用户重定向到 /auth/...
,这样用户就会被重定向到身份验证服务.
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?
推荐答案
在 Angular 1.0.1 中添加 target="_self"
工作:
Adding target="_self"
works in Angular 1.0.1:
<a target="_self" href='/auth/facebook'>Sign in with Facebook</a>
此功能已记录在案(https://docs.angularjs.org/guide/$location - 搜索'_self')
This feature is documented (https://docs.angularjs.org/guide/$location - search for '_self')
如果您好奇,请查看角度源(第 5365 行 @ v1.0.1).点击劫持仅在 !elm.attr('target')
为真时发生.
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.
这篇关于angular.js 链接行为 - 禁用特定 URL 的深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!