有条件地让锚链接将用户发送到不同的页面,而不是加载到 ng-view [英] Conditionally have anchor links send user to a different page, rather than load to ng-view

查看:13
本文介绍了有条件地让锚链接将用户发送到不同的页面,而不是加载到 ng-view的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含锚链接的视图.该链接具有指向我网站中另一个 url 的 href.Angular 尝试使用 html5mode 加载该站点.我宁愿只为该链接设置默认行为并将用户发送到 url.我如何指定这个特定链接的行为应该像一个普通的 html 链接,而不是一个有角度的路由?

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?

推荐答案

AngularJS 了解一些使浏览器执行完全重新加载的规则.这些规则记录在 $location 服务文档.

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.

来自文档:

在以下情况下,链接不会被重写;相反,浏览器将执行完整页面重新加载到原始链接.

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

  • 包含目标元素的链接示例:link
  • 转到不同域的绝对链接示例:link
  • 以/"开头的链接会在定义 base 时指向不同的基本路径示例:link

请注意,最后一个示例仅在您在页面的 head 部分使用了 base 元素时才有效:

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/" />

这篇关于有条件地让锚链接将用户发送到不同的页面,而不是加载到 ng-view的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆