-
Notifications
You must be signed in to change notification settings - Fork 3k
Add global resolve for all routes #3060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @jmanuelrosa can you explain why you want to add new Resolvable to each transition? It's pretty rare you need to do so. Usually you only need to add a normal Transition Hook. I will add an overload to If you're using javascript modules, the |
Hi @christopherthielen, I need to get data from user, if he accesses from a route from my app, and I think that adding a new generic resolve would be the best solution. I try to use |
Regular transition hooks fully support asynchronous operations. $transitions.onStart({}, function(transition) {
// Return a promise; transition waits.
return $http.get('/api').then(function(resp) {
if (resp.data.role !== 'ADMIN') {
// You can redirect ($state.target()) or cancel (return false)
// or you can return another promise to do more async stuff
return $state.target('home');
}
});
}); What are you doing with the data being fetched? If you don't need to display the data in a state's view then you probably don't want to use a resolve. The dynamic resolve is also only available to the states being newly entered (the states being retained are not re-entered) In ui-router legacy versions 0.x, you had no other choice for asynchronous handling than a resolve. But in 1.0 the transition hooks should almost always be the first choice for adding asynchronous handling to a state. |
Wow! Thanks you very much! @christopherthielen ! and, i need to say you taht I love ui-router 😄 |
@christopherthielen If data that is being fetched asynchronously and is not required as part of the component displayed for a given state, you say to put this in a transition. This makes complete sense and makes for a much neater implementation. However, a few questions:
EDIT: I have found an answer to the last question: transition.targetState().name(); Feels strange having to use these as methods - would be nice if they were getters. Any scope for this change? Many thanks for all your hard work on this project! |
To be pedantic, put it in a transition hook. A transition itself is "the process of activating a state".
let deregister = $transitions.onStart({}, trans => {
deregister();
// do stuff with trans
});
Not yet. Follow #2995
Use Transition.to() $transitions.onStart({}, trans => {
let toStateName = trans.to().name;
}); |
Thanks for the through answers and thanks again for your great efforts. |
Still not resolved ! How to inject a resolve function from a decorator ?
then I have this:
But an error occurs due to "translations" that cannot be resolved :-( |
I try to add new resolve for all routes with 1.0.0-beta.3. I read in docs, that we need to use
addResolvable
in$transitions
hook, but, how I can useResolvable
? becauseaddResolvable
need newResolvable
object.Thanks!
The text was updated successfully, but these errors were encountered: