angular.js - angularjs ui-router browser back
ringa_lee
ringa_lee 2017-06-07 09:23:52
0
1
997

<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>

Click the a tag, ui-view displays "Hello", click the browser to go back and "Hello" still exists on the page, why is this?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
phpcn_u1582

It is recommended to read this article first about using angular-ui-router. By default, an initial state needs to be set. See the following usage examples for details.

<!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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template