Javascript 如何制作 Angularjs 嵌套路由?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12790075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Angularjs nested routes?
提问by Cherif BOUCHELAGHEM
I am new to angular, I want to know if angularjs supports nested routes like emberjs I mean routes like this: myappurl/#/company/:company_id/department/:department_id
我是 angular 的新手,我想知道 angularjs 是否支持像 emberjs 这样的嵌套路由,我的意思是这样的路由: myappurl/#/company/:company_id/department/:department_id
采纳答案by Tosh
According to the example given in the document: https://docs.angularjs.org/api/ngRoute/directive/ngView. Yes, Angularjs supports it.
根据文档中给出的示例:https: //docs.angularjs.org/api/ngRoute/directive/ngView。是的,Angularjs 支持它。
回答by artch
It worth mentioning there are another Angular libraries except ui-router
to accomplish this task. This one works too:
值得一提的是,除了ui-router
完成此任务外,还有另一个 Angular 库。这个也有效:
http://angular-route-segment.com
http://angular-route-segment.com
It is much simpler to use than ui-router. Sample route configuration looks like this:
使用起来比 ui-router 要简单得多。示例路由配置如下所示:
$routeSegmentProvider.
when('/section1', 's1.home').
when('/section1/prefs', 's1.prefs').
when('/section1/:id', 's1.itemInfo.overview').
when('/section1/:id/edit', 's1.itemInfo.edit').
when('/section2', 's2').
segment('s1', {
templateUrl: 'templates/section1.html',
controller: MainCtrl}).
within().
segment('home', {
templateUrl: 'templates/section1/home.html'}).
segment('itemInfo', {
templateUrl: 'templates/section1/item.html',
controller: Section1ItemCtrl,
dependencies: ['id']}).
within().
segment('overview', {
templateUrl: 'templates/section1/item/overview.html'}).
segment('edit', {
templateUrl: 'templates/section1/item/edit.html'}).
up().
segment('prefs', {
templateUrl: 'templates/section1/prefs.html'}).
up().
segment('s2', {
templateUrl: 'templates/section2.html',
controller: MainCtrl});
回答by Leon Radley
It can also be worth checking out https://github.com/angular-ui/ui-router