ui-router not producing correct href attribute in angular

巧了我就是萌 提交于 2019-12-08 12:22:52

问题


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


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

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.


回答1:


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

Impossible to disable html5Mode with angular 1.3.0-rc.3 #1397

Due to:

angular/angular.js@dc3de7f

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

A quick fix could be:

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

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

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




回答2:


Try to set the html5Mode in $locationProvider:

$locationProvider.html5Mode(true);

Also, I found this issue, it may be related (I don't know which version you are using):

Impossible to disable html5Mode with angular 1.3.0-rc.3



来源:https://stackoverflow.com/questions/26668065/ui-router-not-producing-correct-href-attribute-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!