ui-router 没有以角度生成正确的 href 属性 [英] ui-router not producing correct href attribute in angular

查看:28
本文介绍了ui-router 没有以角度生成正确的 href 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$stateProvider
  .state('admin', {
    abstract: true,
    url: '/admin',
    template: '<div ui-view></div>'
  })


<a ui-sref="admin">admin</a>

我得到的 url 是 <a href="/admin">admin</a> 而它应该/#/admin -- 当我命令单击链接以在新选项卡中打开时,这会中断.

The url I get is <a href="/admin">admin</a> when it should be /#/admin -- this breaks when I command click on a link to open in a new tab.

推荐答案

这是一个已知问题,报告为错误.将在下一个版本中修复.这是一个解决方法:

This is a known issue, reported as a bug. Will be fixed in next release. Here is a workaround:

由于:

angular/angular.js@dc3de7f

urlRouter.js [line 383] 中的 html5mode-check 不再正确.因此不可能禁用 html5mode.

the html5mode-check in urlRouter.js [line 383] is no longer correct. And thus it's impossible to disable html5mode.

快速解决方法可能是:

var isHtml5 = $locationProvider.html5Mode();
if (angular.isObject(isHtml5)) {
  isHtml5 = isHtml5.enabled;
}

还有 Chris T 的建议 (UI-Router团队成员) - 请参阅此 Q & 下的评论一个

Also there is suggestion by Chris T (UI-Router team member) - see comments under this Q & A

暂时使用预发布版本 0.2.12-pre1.bit.ly/UIR-0212pre1 ...它对 1.3.0 兼容做了一些修复.– 克里斯 T 10 月 16 日 16:13

Use the pre-release version 0.2.12-pre1 for now. bit.ly/UIR-0212pre1 ... it has a few fixes for 1.3.0 compat. – Chris T Oct 16 at 16:13

这篇关于ui-router 没有以角度生成正确的 href 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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