在angular中,继ngRoute后,uiRoute称为更多人使用的路由。
它可以使页面多视图,并且可以多级嵌套。一下是基础格式写法
angular.module('app',['ui.router']).config(function($urlRouterProvier,$stateProvider){ $urlRouterProvier.otherwise('/');//一级路由默认页面 $stateProvider.state('/', url:'', templateurl:'' ) })
但当我们使用的二级路由中嵌套三级路由时,会发现二级页面默认不会显示第三级的页面,也就是二级页面为空,这里我们就要用到
angular.module('app',['ui.router']).config(function($urlRouterProvier,$stateProvider){ $urlRouterProvier.otherwise('/');//一级路由默认页面 $stateProvider.state('a',{ url:'/a', templateurl:'a.html', controller:function($state){ $state.go(a.b) } }) .state('a.b',{ url:'/b', templateUrl:'b.html' }) })
这样就可以完成了