带有 html5Mode 的 Angularjs 普通链接 [英] Angularjs Normal Links with html5Mode
问题描述
我正在 html 5 模式下使用 angularjs.它似乎控制了页面上的所有 href.但是,如果我想要链接到应用程序的同一域中但实际上不在应用程序中的内容,该怎么办.一个例子是 pdf.
I am working with angularjs in html 5 mode. Which appears to take control of all href's on the page. But what if I want to have a link to something within the same domain of the app but not actually in the app. An example would be a pdf.
如果我这样做 <a href="/pdfurl">
angular 只会尝试使用 html5mode 并使用路由提供程序来确定应该加载哪个视图.但我实际上希望浏览器以正常方式访问该页面.
If i do <a href="/pdfurl">
angular will just try to use the html5mode and use the route provider to determine which view should be loaded. But I actually want the browser to go to that page the normal way.
这样做的唯一方法是与路由提供者制定规则并使用 window.location 重定向到正确的页面吗?
Is the only way to do this is to make a rule with the route provider and have that redirect to the correct page with window.location?
推荐答案
在HTML5模式下,A标签没有被重写的三种情况:来自 angular 文档
in HTML5 mode, there are three situations in which the A tag is not rewritten: from the angular docs
- 包含
target
属性的链接.示例:link
- 指向不同域的绝对链接
示例:<a href="http://angularjs.org/">link</a>
- 以/"开头的链接在定义
base
时会导致不同的基本路径示例:<a href="/not-my-base/link">link</a>
- Links that contain a
target
attribute. Example:<a href="/ext/link?a=b" target="_self">link</a>
- Absolute links that point 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 definedExample: <a href="/not-my-base/link">link</a>
所以你的情况是 1. 添加 target="_self"
so your case would be 1. add target="_self"
这篇关于带有 html5Mode 的 Angularjs 普通链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!