我计划在我的大型应用程序中使用AngularJS。所以我正在寻找合适的模块来使用。

ngRoute (angular-route.js)和ui-router (angular-ui-router.js)模块之间的区别是什么?

在许多文章中,当使用ngRoute时,route是用$routeProvider配置的。然而,当与ui-router一起使用时,route使用$stateProvider和$urlRouterProvider配置。

我应该使用哪个模块来获得更好的可管理性和可扩展性?


当前回答

Ui-router是一个第三方模块,功能非常强大。它支持普通ngRoute所能做的一切,以及许多额外的函数。

下面是ui-router选择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,在表下是完全不同的。这些附加特性对于较大的应用程序非常有用。

更多信息:

Github: https://github.com/angular-ui/ui-router 文档: API参考:http://angular-ui.github.io/ui-router/site/#/api 导游:https://github.com/angular-ui/ui-router/wiki 常见问题:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions 示例应用程序:http://angular-ui.github.io/ui-router/sample/#/

其他回答

Ui-router是一个第三方模块,功能非常强大。它支持普通ngRoute所能做的一切,以及许多额外的函数。

下面是ui-router选择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,在表下是完全不同的。这些附加特性对于较大的应用程序非常有用。

更多信息:

Github: https://github.com/angular-ui/ui-router 文档: API参考:http://angular-ui.github.io/ui-router/site/#/api 导游:https://github.com/angular-ui/ui-router/wiki 常见问题:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions 示例应用程序:http://angular-ui.github.io/ui-router/sample/#/

ngRoute是AngularJS核心框架的一部分。

Ui-router是一个社区库,创建它是为了改进默认路由功能。

这是一篇关于配置/设置ui-router的好文章:

http://www.ng-newsletter.com/posts/angular-ui-router.html

ngRoute是一个基本的路由库,你可以为任何路由指定一个视图和控制器。

使用ui-router,你可以指定多个视图,包括并行视图和嵌套视图。因此,如果你的应用程序需要(或将来可能需要)任何复杂的路由/视图,那么就使用ui-router。

这是AngularUI路由器最好的入门指南。

ngRoute是AngularJS团队开发的一个模块,它是AngularJS核心的早期部分。

ui-router是AngularJS项目之外的一个框架,用于改进和增强路由功能。

来自ui-router文档:

AngularUI路由器是AngularJS的路由框架,它允许 您可以将接口的各个部分组织到状态机中。 不像Angular核心中的$route服务,它是围绕 URL路由,UI-Router是围绕状态组织的,这可能是可选的 附加路由和其他行为。 状态被绑定到命名的,嵌套的和并行的视图,允许您 强大地管理应用程序的界面。

它们都不是更好的,你必须选择最适合你的项目。

但是,如果您计划在应用程序中使用复杂的视图,并且希望处理“$state”概念。我建议你选择ui-router。

角1.倍

ng-route:

ng-route由angularJS团队开发用于路由。

ng-route:基于url位置的路由。

Ex:

$routeProvider
    .when("/home", {
        templateUrl : "home.html"
    })

ui-route:

ui路由器由第三方模块开发。

Ui-router:基于状态的路由

Ex:

 $stateProvider
        .state('home', {
            url: '/home',
            templateUrl: 'home.html'
        })

——> ui-router允许嵌套视图

——> ui-router比ng-route更强大

ng-router, ui-router