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

查看:423
本文介绍了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)模块?

在许多文章中 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 是第三方模块,功能非常强大。它支持正常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 。对于URL可能发生变化的大型项目非常有用。

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.

状态允许您映射和访问有关不同状态的不同信息,您可以通过 $ stateParams

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

您可以轻松确定您是否处于状态或父状态,以通过模板调整UI元素(突出显示当前状态的导航) $ state ui-router提供的 ,你可以在运行 $ rootScope 中设置它c $ c>。

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,在表单下它是相当的DIFF erent。这些附加功能对于大型应用程序非常有用。

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天全站免登陆