Ui-sref 未在 URL 中生成哈希(Angular 1.3.0-rc.3)URL、sref、Ui、rc

2023-09-06 14:42:32 作者:叫哥丶小笨蛋

自从从 Angular 1.3.0 RC-2 升级到 RC-3 后,我的链接中由 ui-sref 生成的哈希符号已经消失.该链接是可点击的,并且状态转移正确发生,但是如果我复制链接地址并将其粘贴到浏览器中,它将进入错误的页面.我不想使用 HTML5Mode.

Since upgrading from Angular 1.3.0 RC-2 to RC-3 the hash-sign in my links generated by ui-sref has disappeared. The link is clickable and the state transfers happens correctly, but if i copy the link address and paste it in a browser it will land on the wrong page. I dont want to use HTML5Mode.

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 演示工作示例

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 演示问题

是我做错了什么,还是 ui-router 与 Angular 的最新候选版本不兼容?

Am i doing something wrong, or is ui-router not compatible with the latest release candidate of Angular?

推荐答案

这是一个已知问题.它已在 master 中修复.https://github.com/angular-ui/ui-router/issues/1397

That's a known issue. It's fixed in master. https://github.com/angular-ui/ui-router/issues/1397

Angular 1.3 更改了 HTML5 模式 API,UI-Router 必须支持任一 API.

Angular 1.3 changed the HTML5 mode API, and UI-Router has to support either API.

 
精彩推荐
图片推荐