问题

我是AngularJS的新手.我发现AngularJS相当有趣,我计划在我的大应用程序中使用AngularJS.所以我正在找到正确的模块使用.

ngRoute(angular-route.js) ui-router(angular-ui-router.js)模块有什么区别?

在许多文章中,如果使用ngRoute ,系统会使用 $ routeProvider 来配置路线.但是,当与 ui-router 配合使用时,路由配置为 $ stateProvider和$ urlRouterProvider .

这给我造成了一些困惑.我应该使用哪个模块来提高可管理性和可扩展性?



解决方法

ui-router 是第三方模块,功能非常强大.它支持正常的ngRoute可以做的一切,以及许多额外的功能.

这里是一些常见的原因ui路由器选择ngRoute:

  • ui-router allows for nested views and multiple named views. This is very useful with larger app where you may have pages that inherit from other sections.

  • ui-router allows for you to have strong-type linking between states based on state names. Change the url in one place will update every link to that state when you build your links with ui-sref. Very useful for larger projects where URLs might change.

  • 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 allow you to map and access different information about different states and you can easily pass information between states via $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具有更多的功能,在sheet下是非常不同的.这些附加功能对于大型应用程序非常有用.

详细信息:




相关问题推荐