Angularjs没有预定义的路线

时间:2016-12-05 14:33:47

标签: javascript angularjs regex angular-ui-router angular-routing

我正在玩角度试图创建一些路线,而没有静态指定路径

我现在有以下ng-routes:

route
.when("path/of/first/file",{templateUrl: "path/of/first/file.html"})
.when("path/of/second/file",{templateUrl: "path/of/second/file.html"})
.when("path/of/third/file",{templateUrl: "path/of/third/file.html"})

正如您在本示例中所看到的,每个文件都有一个固定的规则:

path/of/%dynamic_path%/file  -> path/of/%dynamic_path%/file.html

所以我应该有像regexp这样的东西:

route.when("path/of/(.*)/file",{templateUrl: "path/of/$1/file.html"});

我希望能够添加路径,而无需在路由器配置中指定它们(假设我有数千个文件)。有没有什么东西可以让我在角度路线或ui路线上做到这一点?

1 个答案:

答案 0 :(得分:-1)

您想要动态路由,请参阅this                      - RamblinRose