Skip to content

State specific rules and redirects #665

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

Closed
josh-hobson opened this issue Dec 10, 2013 · 4 comments
Closed

State specific rules and redirects #665

josh-hobson opened this issue Dec 10, 2013 · 4 comments

Comments

@josh-hobson
Copy link

I have run into a problem in my app using ui-router where I need state specific rules to determine whether or not a user is allowed to view a certain page in the app.

This is the question I asked on stack overflow: http://stackoverflow.com/questions/20472136/state-specific-rules-and-redirects

Having looked through the source however it looks like this can't be done. I could use urlRouterProvider to create rules however the app has a large state tree and requires data loaded in resolves of previous states to calculate the rules of its children. As far as I'm aware, urlRouter is hit first when a new location is provided so in some cases the required data may not have been loaded yet (for example, navigating directly to the url).

A quick example of the use case would be a questionnaire where you don't want the customer to go to page n+1 without having completed page n. A rule on the page state would allow you to quickly check which page they should be viewing.

I believe this could also be useful in other cases, such as having a rule to provide a default child state for an abstract state if no child was provided.

I am willing to put in the time to try and work out how to do this, I'm new to angular UI but would enjoy the work. However I just thought it would be worth checking that:
a) I haven't missed a feature that would achieve this,
b) Someone isn't already working on this,
c) There aren't any reasons against doing state specific rules, philosophical or otherwise.

@nateabele
Copy link
Contributor

This can already be accomplished by attaching custom data to states using the data key (these could even be functions), and then intercepting state transitions with $stateChangeStart and using the state's custom data to evaluate rules. If you have a specific proposal, add some example code to demonstrate how it would work, or close this issue and continue the discussion here: #618 (comment)

@josh-hobson
Copy link
Author

Thanks @nateabele. I assumed someone had probably already asked this but just couldn't find an issue regarding it.

For now I will use the state change event, however I will also contribute to the discussion and provide some code for how I would implement it.

@timkindberg
Copy link
Contributor

@josh-hobson if you are feeling crazy, please feel free to add an item on this topic to the FAQ.

@nateabele
Copy link
Contributor

@josh-hobson Yeah, this is still pretty open territory, and I'd be happy to help collaborate on a 3rd-party module if some common patterns emerge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants