angularjs - Angular UI 路由器 : Back-button not working for simple code

标签 angularjs angular-ui-router

这个简单的代码有两个链接,“状态 1”和“状态 2”。

当我点击“State 1”时,它打印出“This is the first state”。 当我点击“State 2”时,它打印出“This is the secondary state”。

但是当我单击浏览器的后退按钮时,它仍然显示“这是第二个状态”。难道不应该改成“这是第一个状态”吗?

代码笔:http://codepen.io/anon/pen/bCohi

代码:

<html>
<head>
  <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js'></script>  
  <script type="text/javascript" src='http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js'></script>
</head>
<body ng-app="myApp">
  <a ui-sref="state1">State 1</a>
  <a ui-sref="state2">State 2</a>
  <br>
  <ui-view></ui-view>
  <script>
  var myApp = angular.module("myApp", ['ui.router']);

  myApp.config(function($stateProvider, $urlRouterProvider) {
    var stateProvider = $stateProvider;
    stateProvider.state('state1', {
      url: 'state-1',
      template: 'This is the first state'
    });
    stateProvider.state('state2', {
      url: 'state-2',
      template: 'This is the second state'
    });
  });
  </script>
</body>
</html>

最佳答案

哦 - 我明白了。

url: 'state-1',
. . . . . . . . . .
url: 'state-2',

应该是

url: '/state-1',
. . . . . . . . . .
url: '/state-2',

关于angularjs - Angular UI 路由器 : Back-button not working for simple code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24809261/

相关文章:

AngularJS : UI Router Silently failing

javascript - 从index.html调用函数并且函数无限循环

angularjs - 在 angularjs 中强制异步验证器

javascript - 重新加载 angularjs 中的选项卡

AngularJS ui-router 状态不会在后面刷新

javascript - 验证 AngularJS 状态更改时的登录效果不佳

json - AngularJS:如何获取 JSON 对象的键

angularjs - 无法读取 $httpInterceptor 中未定义的属性 'push'

angularjs - $state,$stateParams,获取 undefined object

javascript - Angular-meteor 授权 - 在加载页面之前检查用户角色