一、基本用法

$stateProvider.state(stateName, stateConfig)
stateName是string类型
stateConfig是object类型
statConfig可以为空对象,如$stateProvider.state(“home”,{});
state可以有子父级
$stateProvider.state(“home”,{});
$stateProvider.state(“home.child”,{})
//state可以是链式的
$stateProvider.state(“home”,{}).state(“about”,{}).state(“photos”,{});
stateConfig包含的字段:template, templateUrl, templateProvider, controller, controllerProvider, resolve, url, params, views, abstract, onEnter, onExit, reloadOnSearch, data

$urlRouteProvider.when(whenPath, toPath)
$urlRouterProvider.otherwise(path)
$urlRouteProvider.rule(handler)
$state.go
$state.go(to, [,toParams],[,options])
形参to是string类型,必须,使用”^”或”.”表示相对路径;
形参toParams可空,类型是对象;
形参options可空,类型是对象,字段包括:location为bool类型默认true,inherit为bool类型默认true, relative为对象默认$state.$current,notify为bool类型默认为true, reload为bool类型默认为false

$state.go(‘photos.detail’)
$state.go(‘^’)到上一级,比如从photo.detail到photo
$state.go(‘^.list’)到相邻state,比如从photo.detail到photo.list
$state.go(‘^.detail.comment’)到孙子级state,比如从photo.detail到photo.detial.comment

 

ui-sref
ui-sref=’stateName’
ui-sref=’stateName({param:value, param:value})’

二、完整实例

目录结构:

index.html

content.html

header.html

home.html


params.html

 

about.html

其他页面省略…,功能可根据需要自己写,我只是记笔记。

app.js

 

更多API参考,请点击这里