在没有状态定义的情况下使用ui-sref路由到默认模板的任何方法?

时间:2015-09-18 22:50:14

标签: angularjs angular-ui-router

我有一系列的状态如下:

.state('welcome', {
        url: "^/welcome",
        views: {
            "@": {
                templateUrl: "components/welcome/welcome.html",
                controller: "WelcomeController as welcome"
            }
        }
 })
.state('welcome.step1', {
    templateUrl: "components/welcome/welcome.step1.html"
})
.state('welcome.step2', {
    templateUrl: "components/welcome/welcome.step2.html"
})

在我看来,我可以使用ui-sref="welcome.step2"从步骤1转到第2步。

然而,当文件结构暗示状态时,为每个步骤定义状态似乎有些过分。

我认为路由器足够智能,但我可能会想到 ng-route

有没有办法避免使用单个模板定义这样的简单路由?

1 个答案:

答案 0 :(得分:1)

只需使用循环来定义状态:

for (var step = 1; step <= 10; step++) {
     $stateProvider.state('welcome.step' + step, {
         templateUrl: "components/welcome/welcome.step" + step + ".html"
     });
}
相关问题