angular-route 和 angular-ui-router 有什么区别? [英] What is the difference between angular-route and angular-ui-router?

查看:25
本文介绍了angular-route 和 angular-ui-router 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在我的大型应用程序中使用 AngularJS.所以我正在寻找要使用的正确模块.

I'm planning to use AngularJS in my big applications. So I'm in the process to find out the right modules to use.

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

What is the difference between ngRoute (angular-route.js) and ui-router (angular-ui-router.js) modules?

在很多使用ngRoute的文章中,路由是用$routeProvider配置的.但是,当与 ui-router 一起使用时,路由配置为 $stateProvider 和 $urlRouterProvider.

In many articles when ngRoute is used, route is configured with $routeProvider. However, when used with ui-router, route is configured with $stateProvider and $urlRouterProvider.

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

Which module should I use for better manageability and extensibility?

推荐答案

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

ui-router is a 3rd-party module and is very powerful. It supports everything the normal ngRoute can do as well as many extra functions.

以下是选择 ui-router 而不是 ngRoute 的一些常见原因:

Here are some common reason ui-router is chosen over 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 允许您根据状态名称在状态之间建立强类型链接.当您使用 ui-sref.对于网址可能会更改的大型项目非常有用.

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.

还有decorator 可用于允许根据尝试访问的 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.

states allow you to map and access different information about different states and you can easily pass information between states via $stateParams.

您可以通过 $state 由 ui-router 提供可以通过在 run 上的 $rootScope 中设置它来公开.

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下就大不一样了.这些附加功能对于大型应用程序非常有用.

In essence, ui-router is ngRouter with more features, under the sheets it is quite different. These additional features are very useful for larger applications.

更多信息:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆