【发布时间】:2016-06-10 09:54:54
【问题描述】:
我正在使用 Angular js 编写一个简单的产品信息管理应用程序。为了使我的应用程序尽可能模块化,我将其拆分为多个模块,其中一个模块“pim”作为起点。对于每个模块,我希望有不同的路由,以便轻松插入新模块或删除它,而无需在 pim 模块配置中维护巨大的路由。
目前我有两条路线(第一条路线):
(function(){
angular
.module("pim")
.config(router)
function router($routeProvider){
$routeProvider
.when("/",{
templateUrl: "view/info.html",
controller: "pimController"
})
.when("/info",{
templateUrl: "view/info.html",
controller: "pimController"
})
.when("/alcohol",{
templateUrl: "view/alcohol.list.html",
controller: "alcoholController"
});
}
})();
第二条路线
(function(){
angular
.module("alcohol")
.config(router)
function router($routeProvider){
$routeProvider
.when("/alcohol/list",{
templateUrl: "view/alcohol.list.html",
controller: "alcoholController"
})
.when("/alcohol/info",{
templateUrl: "view/alcohol.info.html",
controller: "alcoholController"
});
}
})();
如您所见,/alcohol 有一个 templateUrl 和一个控制器,与 /alcohol/list 相同,但我想知道是否有一种简单(标准)的方法可以更改为另一个 URL,例如 /alcohol/list,这样我就不必重复 templateUrl 和控制器,并将这些信息保存在它所属的酒精模块中。
例如
.when("/alcohol",{
routeTo: "/alcohol/list"
})
感谢您的帮助
已解决
存在重定向选项,在 $routeProvider 文档中看的不够好:
.when("/alcohol",{
redirectTo:"/alcohol/list"
});
上面的代码有效
【问题讨论】:
标签: javascript angularjs angular-ui-router