1

I am building small app using angularjs and nodejs and i would like to know what is best use case for $stateprovider and $routeProvider.

Please help

khajaamin
  • 856
  • 7
  • 18
  • http://stackoverflow.com/questions/19388852/to-routeprovider-or-stateprovider – ddepablo Mar 23 '16 at 13:21
  • Possible duplicate of [What is the difference between $routeProvider and $stateProvider in AngularJs](http://stackoverflow.com/questions/27645202/what-is-the-difference-between-routeprovider-and-stateprovider-in-angularjs) – Kailas Mar 23 '16 at 13:24

3 Answers3

1

Angular's own ng-Router takes URLs into consideration while routing, UI-Router takes states in addition to URLs.

States are bound to named, nested and parallel views, allowing you to powerfully manage your application's interface.

While in ng-router, you have to be very careful about URLs when providing links via tag, in UI-Router you have to only keep state in mind. You provide links like . Note that even if you use in UI-Router, just like you would do in ng-router, it will still work.

So, even if you decide to change your URL some day, your state will remain same and you need to change URL only at .config.

While ngRouter can be used to make simple apps, UI-Router makes development much easier for complex apps.

Arizona2014
  • 1,317
  • 2
  • 18
  • 33
1

$stateprovider is used when you want the app to have different states like if you want jst a small section of a screen to be loaded at times instead of the entire screen, the go for State provider and the $state.go(url). Special cases when you have a Sliding Drawer sort of an implementation, where you have a right menu with buttons which load different sub screens.

$routeProider are commonly used. Mostly when you want the entire screen to be changed and redirected to a new one.

Note
While using the $state.go(url); for redirecting your screen, the real link of your screen won't change. It will just change the state and not the url of the page

Kailas
  • 7,350
  • 3
  • 47
  • 63
0

Not to confuse the issue, but there is a new option in AngularJS 1.5: ComponentRouter

This router, along with the uiRouter ($stateProvider) give you more flexibility than the legacy ngRouter ($routeProvider). The ComponentRouter and uiRouter both have a future if you migrate to Angular2.

That said, it depends on your needs. You may not need the composable and nested views offered by ComponentRouter and uiRouter -- but instead only need simple routes.

Martin
  • 15,820
  • 4
  • 47
  • 56