Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to $routeProvider or $stateProvider

I have been looking for a sound answer to to this dilema, to routeProvider or not to.

It appears as if $routeProvider is soon going to be discontinued and replace with $stateProvider unfortunately I don't know the accuracy of this statement plus stateProvider is still only available via ui_router plugin.

Is the plan to add stateProvider as part of the AngularJS Core? Is it save to assume that it will soon replace the old $routeProvider?

They certainly don't play well together and the migration CI that I found in github doesn't work and lacks documentation.

like image 763
J Castillo Avatar asked Oct 15 '13 18:10

J Castillo


People also ask

What is the difference between $stateprovider and $routeprovider?

According the documentation $routeProvider is a routing standard for now, this approach is also used in official tutorial. But… Like with all the things, $routeProvider was not perfect. The $routeProvider is dead, long live the $stateProvider! $stateProvider allows us to give names for routes.

What happened to the $routeprovider?

The $routeProvider is dead, long live the $stateProvider! $stateProvider allows us to give names for routes. Having a name we can duplicate the route with another name assign different controller, view, well.. we can do whatever we want! It means… with this approach we have different states of the route, thats why its called $stateProvider.

Can I use $urlrouterprovider with UI-router?

According to the ui-router docs, you should use ui-router 's own implementation of $routeProvider, called $urlRouterProvider. Mostly correct: they aren't intended to be used together, however, ui.router exposes a $routeProvider as part of its compatibility layer for use when migrating from ngRoute.

What is the use of $routeprovider in Salesforce?

$routeProvider is a function under config (mainApp module) using the key as ‘$routeProvider’. $routeProvider.when defines the URL “/addStudent”. The default view is set by “otherwise”. “controller” is used for the view.


2 Answers

After a very long time we decided to bite the bullet and migrate from 1.1.1 to 1.2. At the same time we realized how limited $routerProvider really is so we went with ui-router. So far, we love it, it allows you to do some complex nesting in the views plus add a bit more structure to your app, for example, in $stateProvider you can define onEnter and onExit which allows you to modify your data and restore it upon exiting, you can also transitionTo state which is extremely powerful. I would vote for ui-router to be part of Angular core and even replace $routeProvider. I hope this helps you made up your mind. $routeProvider still works, if you have a basic app or demo page.

like image 180
J Castillo Avatar answered Oct 06 '22 00:10

J Castillo


We started with $routeProvider and moved to $stateProvider to leverage some of the features that ui-router provides. When we moved the migration was absolutely trivial. Having said that, ui-router is still very early (from their GitHub page):

Warning: UI-Router is pre-beta and under active development. As such, while this library is well-tested, the API is subject to change. Using it in a project that requires guaranteed stability is not recommended.

Stick with $routeProvider until you decide you need something else. Until then, make sure you are getting good test coverage so that shifts like that aren't too big of a concern.

like image 23
mfollett Avatar answered Oct 06 '22 02:10

mfollett