2014-10-06 47 views
5

由於從Angular 1.3.0 RC-2升級到RC-3,我的鏈接中由ui-sref生成的哈希符號消失了。鏈接是可點擊的,並且狀態轉移正確發生,但是如果我複製鏈接地址並將其粘貼到瀏覽器中,它將落在錯誤的頁面上。我不想使用HTML5Mode。Ui-sref不會在URL中生成哈希值(Angular 1.3.0-rc.3)

1.3.0 rc.2

<!DOCTYPE html> 
    <html> 

     <head> 
     <link rel="stylesheet" href="style.css"> 
     </head> 

     <body ng-app="myApp"> 

     <div ui-view></div> 
     <script src="https://code.angularjs.org/1.3.0-rc.2/angular.js"></script> 
     <script src="https://rawgit.com/angular-ui/ui-router/0.2.11/release/angular-ui-router.js"></script> 
     <script> 
      angular.module('myApp', ['ui.router']) 
      .config(function($stateProvider, $urlRouterProvider, $locationProvider) { 


      $urlRouterProvider.otherwise('/foo'); 

      $stateProvider.state('foo', { 
       url: '/foo', 
       template: 'This is foo <a ui-sref="foo.bar">Go to bar</a><div ui-view></div>' 
      }) 
      .state('foo.bar', { 
       url: '/bar', 
       template: 'This is bar' 
      }) 

      $locationProvider.html5Mode(false); 
      //$locationProvider.html5Mode({ enabled: false }) 
      }); 
     </script> 

     </body> 

    </html> 

Plunkr demonstrating working example

1.3.0 rc.4

<!DOCTYPE html> 
    <html> 

     <head> 
     <link rel="stylesheet" href="style.css"> 
     </head> 

     <body ng-app="myApp"> 

     <div ui-view></div> 
     <script src="https://code.angularjs.org/1.3.0-rc.4/angular.js"></script> 
     <script src="https://rawgit.com/angular-ui/ui-router/0.2.11/release/angular-ui-router.js"></script> 
     <script> 
      angular.module('myApp', ['ui.router']) 
      .config(function($stateProvider, $urlRouterProvider, $locationProvider) { 


      $urlRouterProvider.otherwise('/foo'); 

      $stateProvider.state('foo', { 
       url: '/foo', 
       template: 'This is foo <a ui-sref="foo.bar">Go to bar</a><div ui-view></div>' 
      }) 
      .state('foo.bar', { 
       url: '/bar', 
       template: 'This is bar' 
      }) 

      //$locationProvider.html5Mode(false); 
      $locationProvider.html5Mode({ enabled: false }) 
      }); 
     </script> 

     </body> 

    </html> 

Plunkr demonstrating the problem

我做得不對,或者是ui-router與最新的Angular版本不兼容?

回答

6

這是一個已知的問題。它已在master中修復。 https://github.com/angular-ui/ui-router/issues/1397

Angular 1.3更改了HTML5模式API,並且UI-Router必須支持任一API。

+0

這是一個快速複選標記。 heh – 2014-10-06 20:50:46

+0

我已經標記了0.2.12的預發佈版本:http://bit.ly/UIR-0212pre1 – 2014-10-16 16:01:42