这个简单的代码有两个链接,“状态 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/