<body>
<p ui-view></p>
<a ui-sref="test">点击</a>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state("test", {
url: '/test',
template:'<p>你好</p>',
});
});
</script>
點擊a標籤,ui-view顯示“你好”,點擊瀏覽器後退“你好”還存在頁面上,這是為什麼?
phpcn_u15822017-06-07 09:25:52
建議先看一下,這篇文章 angular-ui-router使用。預設的話都需要設定一個初始狀態的哈,具體看一下下面的使用範例。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>UI-Router</title>
<script src="https://cdn.bootcss.com/angular.js/1.6.3/angular.min.js"></script>
<script src="https://cdn.bootcss.com/angular-ui-router/1.0.3/angular-ui-router.min.js"></script>
</head>
<body ng-app="myApp">
<p ui-view></p>
<a ui-sref="login">登录页</a>
<a ui-sref="home">首页</a>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state("home", {
url: '/home',
template: '<p>首页</p>',
})
.state("login", {
url: '/login',
template: '<p>登录页</p>',
})
;
$urlRouterProvider.otherwise('/login');
});
</script>
</body>
</html>