Skip to content

$state.transitionToUrl - to return the path/url of a transition #55

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
dbrans opened this issue Mar 19, 2013 · 7 comments
Closed

$state.transitionToUrl - to return the path/url of a transition #55

dbrans opened this issue Mar 19, 2013 · 7 comments

Comments

@dbrans
Copy link

dbrans commented Mar 19, 2013

Sometimes I would prefer to use <a href> with the appropriate path/url instead of calling $state.transitionTo(state).

For this purpose, it would be nice to have an equivalent $state.transitionToUrl and some helpers to get the transition urls for

  • the parent state
  • a child state
  • an arbitrary state

Here is an example of the api:

$state.transitionToUrl = function(to, toParams) {
};

$state.transitionToChildUrl = function(childName, childParams) {
};

$state.transitionToParentUrl = function() {
};

Would others find this useful?

@ksperling
Copy link
Contributor

Essentially that is what issue #16 is about, even though the plan was to expose it as a directive. There is no reason why we can't have both a function and a directive (which uses the function).

Are there any particular use cases where a function would be preferable over a directive?

@dbrans
Copy link
Author

dbrans commented Mar 20, 2013

#16 is cool, I hadn't seen that.

A couple of cases where a function would be preferred:

  1. You don't want the scope to know about state parameters
  2. the transition parameters are difficult to compute within the context of a template.

In any case, exposing more of the currently hidden helper functions (like this transitionUrl function or "findState") would make ui.state easier to use.

@ksperling
Copy link
Contributor

Closing this, @nateabele 's $state.href() has been merged

@morgs32
Copy link

morgs32 commented Aug 6, 2013

@ksperling and @dbrans - Here's a use case. I'd like to reroute someone from within a resolve function inside an abstract state. I can get a $stateParam from injecting it into the resolve. But, the $state.current is an empty string (I'm assuming because it's abstract). I could use the url to redirect thought ($location.path.replace()). Thoughts?

@nateabele
Copy link
Contributor

I don't really understand why you'd do a redirect within a resolve instead of, for example onEnter. I know @ksperling is working on a refactor of transitionTo() which will use an event object containing information on the current transition. That sounds like something that would be more appropriate for your use case.

@morgs32
Copy link

morgs32 commented Aug 6, 2013

I wouldn't mind using onEnter but it doesn't give me the current state name either (just checked), in both abstract states or not. The only thing I have to tell me the current state is the URL.

@morgs32
Copy link

morgs32 commented Aug 6, 2013

I agree I should wish @ksperling good luck with his work on transitionTo()

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

4 participants