Lib: https://github.com/angular-ui/ui-router
使用執行個體:
// Some state name examples
// stateName can be a single top-level name (must be unique).
$stateProvider.state("home", {});
// Or it can be a nested state name. This state is a child of the
// above "home" state.
$stateProvider.state("home.newest", {});
// Nest states as deeply as needed.
$stateProvider.state("home.newest.abc.xyz.inception", {});
// state() returns $stateProvider, so you can chain state declarations.
$stateProvider
.state("home", {})
.state("about", {})
.state("contacts", {});
參數化配置:
var urls = ['news-1' ,'news-2', 'news-3'];
angular.forEach(urls, function(v) {
$stateProvider
.state(v, {
url: '/' + v,
views: {
'aboutBody': { templateUrl: templateBasePath + v }
}
});
});
若有疑問,請發表評論或添加微信為你解答:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiInBnaucDMmBzNzQWO4IGZj1iYjZTOtMWN3MTL1kTZk1SOwIjN3AjYh9CX3gDNy8CXzETMw8CX05WZth2YhRHdh9CXkF2bsBXdvwVbvNmLllXZ0lmLywGZvw1LcpDc0RHaiojIsJye.jpg)