AngularJS:高度动态路由 [英] AngularJS: Highly Dynamic Routing
问题描述
我目前正在寻求实现这样的东西 (AngularJS):
$routeProvider.when('/root/:controllerName/blah/:blahId/blah/:blah', {templateUrl: '/tmpl/:controllerName/blah/partials/:blah' + '.html',控制器: ':controllerName' + 'Ctrl'})
这可能过于复杂(带有废话、废话、废话"),但我想确保它清楚.
简而言之,我的目标是实现与Microsoft MVC如何使用其到控制器的路由类似(足够)的东西——换句话说,非常自主:
routes.MapRoute("Default",//路由名称"{controller}/{action}/{id}",//带参数的 URLnew { controller = "Home", action = "Index", id = "" }//参数默认值);
在那之后,我打算 LazyLoad 控制器(我已经有了),但这需要(希望)与 LazyLoading 兼容.
有没有人用这种方法成功过,知道任何资源,或者对如何实现这一点有任何想法?
--感谢
我认为您无法使用 ngRoute 解决此问题,但我认为 ngInclude 应该是能够提供帮助:
HTML
控制器
$scope.template.url = "";//一些动态规则
这里是关于这个的角度文档的链接:
https://docs.angularjs.org/api/ngRoute/directive/ngView
Hi,
I am currently looking to implement something like this (AngularJS):
$routeProvider
.when('/root/:controllerName/blah/:blahId/blah/:blah', {
templateUrl: '/tmpl/:controllerName/blah/partials/:blah' + '.html',
controller: ':controllerName' + 'Ctrl'
})
This is probably overly complicated (with the 'blah, blah, blah') but I wanted to make sure it is clear.
In a nutshell, I'm aiming to accomplish something similar (enough) to how Microsoft MVC employs their routing to controllers -- in other words, very autonomous:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
After that, I intend to LazyLoad the controller (which I have already), but this needs to be (hopefully) compatible with LazyLoading.
Has anyone had success with this approach, know of any resources, or have any ideas about how to accomplish this?
--PreThanks
I do not think you will be able to resolve this using ngRoute but I think ngInclude should be able to help:
Html
<div class="slide-animate-container">
<div ng-include="template.url"></div>
</div>
Controller
$scope.template.url = "";//some dynamic rules
Here is a link to angular documentation on this:
https://docs.angularjs.org/api/ngRoute/directive/ngView
这篇关于AngularJS:高度动态路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!