Difference between angular-route and angular-ui-router

轉摘:http://stackoverflow.com/questions/21023763/difference-between-angular-route-and-angular-ui-router

Difference between angular-route and angular-ui-router

I am new to AngularJS. I find Angular quite interesting and planning to use angular in my big apps. So I am in the process to find out the right modules to use.javascript

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

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.git

This creates a bit of confusion for me. Which module should I use for better manageability and extensibility? Your answers are greatly appreciated.angularjs

share improve this question
 
    
not to mention angular's new router in 1.4+ and 2.0 –  Zach L May 12 at 21:55

7 Answers

up vote 363down voteaccepted

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.github

Here are some common reason ui-router is chosen over ngRoute:api

  • 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.app

  • 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.ide

  • 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.post

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

  • 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.

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.

More Information:

share improve this answer
 
52  
Overall this is the best explanation, but for one key point: "Overall, ui-router is ngRouter with more features". It's much more fundamental than that: ngRoute merely allows you to assign controllers and templates to URL routes, whereas the fundamental abstraction in ui.router is states, which is a more powerful concept. –  Nate Abele Jan 11 '14 at 4:03 
相關文章
相關標籤/搜索