ui-router 笔录
HTML
<div ng-app="app">
<a ui-sref="home" ui-sref-active="active">home</a>
<a ui-sref="about" ui-sref-active="active">About</a>
<ui-view></ui-view>
</div>
JS
var myApp = angular.module('app', ['ui.router'])
myApp.config(function($stateProvider) {
var homeState = {
name: 'home',
url: '/home',
template: home
}
var aboutState = {
name: 'about',
url: '/about',
template: about
}
var stateArr = [
homeState,aboutState
]
stateArr.forEach(function(e){
$stateProvider.state(e)
})
})
重定向
myApp.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$urlRouterProvider
// 路由重定向
.when('/', '/home')
.otherwise('/');
}
])