我计划在我的大型应用程序中使用AngularJS.所以我正在寻找合适的模块来使用.
ngRoute (angular-route.js)模块和ui-router (angular-ui-router.js)模块有什么区别?
在许多文章中,当使用ngRoute时,路由配置为$routeProvider.然而,当与ui-router一起使用时,路由配置为$stateProvider and $urlRouterProvider.
我应该使用哪个模块来提高可管理性和可扩展性?
我计划在我的大型应用程序中使用AngularJS.所以我正在寻找合适的模块来使用.
ngRoute (angular-route.js)模块和ui-router (angular-ui-router.js)模块有什么区别?
在许多文章中,当使用ngRoute时,路由配置为$routeProvider.然而,当与ui-router一起使用时,路由配置为$stateProvider and $urlRouterProvider.
我应该使用哪个模块来提高可管理性和可扩展性?
ui-router是第三方模块,功能非常强大.它支持普通的ngRoute所能做的一切,以及许多额外的功能.
以下是 Select UI-Router而不是ngRoute的一些常见原因:
用户界面路由允许nested views和multiple named views.这对于较大的应用程序非常有用,因为在这些应用程序中,你可能会有从其他部分继承的页面.
ui路由允许基于状态名称在状态之间进行强类型链接.在一个地方更改url将在您使用ui-sref
创建链接时更新每个链接到该状态.对于URL可能更改的大型项目非常有用.
There is also the concept of the decorator which could be used to allow your routes to be dynamically created based on the URL that is trying to be accessed. This could mean that you will not need to specify all of your routes before hand.
states允许您映射和访问关于不同州的不同信息,您可以通过$stateParams
在州与州之间轻松传递信息.
You can easily determine if you are in a state or parent of a state to adjust UI element (highlighting the navigation of the current state) within your templates via $state
provided by ui-router which you can expose via setting it in $rootScope
on run
.
从本质上讲,UI-Router是功能更多的ngRouter,在表下则大不相同.这些附加功能对于较大的应用程序非常有用.
更多信息: