Currently in some of my controllers I have a logic that e.g. redirects user to a different route if some conditions are met.
I'm trying to move some of this logic from controllers to route.resolve
to prevent showing the "invalid" view and then redirecting user somewhere else.
I already handle authentication in route.resolve
, but that's just a single line - authService.requireUser()
. In case of more complex logic e.g. I need to have the current user object, fetch some resources based on route params, do some calculations on the result, redirect user to one place if some condition is met, redirect to another otherwise etc. Basically it's a lot of code and putting it all into route definitions seems not very clean.
Does anyone have a solution how to handle it? Maybe use separate "route resolver" objects? Or maybe it's better to leave it in a controller and use a flag (isLoaded
) to show a spinner while page is loading and display the proper view only once everything has finished loading?