Skip to content
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

willTransition is not called on first call of transitionTo #38

Closed
oliverwoodings opened this issue Aug 5, 2014 · 6 comments
Closed

Comments

@oliverwoodings
Copy link
Contributor

I may just have a misunderstanding of the purpose of willTransition here, but I would have thought that willTransition would be called whenever a transition occurs?

Example of what I am seeing:

router.addRoute("foo", Route.extend({
  willTransition: function () {
    console.log('bar');
  }
});

router.startRouting();
router.transitionTo("foo");
router.transitionTo("foo");

The above example will only log bar once.

@KidkArolis
Copy link
Contributor

Its only called when transitioning away from the route - its actually an
event and not a regular method, I should probably make it look more like
that. Activate is called when entering the route.
I'll clarify the docs.

I may just have a misunderstanding of the purpose of willTransition here,
but I would have thought that willTransition would be called whenever a
transition occurs?

Example of what I am seeing:

router.addRoute("foo", Route.extend({
willTransition: function () {
console.log('bar');
}
});

router.startRouting();
router.transitionTo("foo");
router.transitionTo("foo");

The above example will only log bar once.


Reply to this email directly or view it on GitHub
#38.

@oliverwoodings
Copy link
Contributor Author

Ohhhh ok that makes sense. So can you do transition.abort in activate?

@KidkArolis
Copy link
Contributor

I think beforeModel or model hooks are best for redirects if that's what
you're trying to do. Abort in activate might work, not sure.
On Aug 6, 2014 9:06 AM, "Oliver Woodings" notifications@github.com wrote:

Ohhhh ok that makes sense. So can you do transition.abort in activate?


Reply to this email directly or view it on GitHub
#38 (comment)
.

@oliverwoodings
Copy link
Contributor Author

Yeah basically I don't want to go into a certain resource if the user isn't authenticated since fetching the models won't work unless you are authenticated

@KidkArolis
Copy link
Contributor

BeforeModel is intended for such cases. Activate hook is called when all
routes have already resolved the model, so too late to redirect in your
case. Btw you don't need to abort, you can just call this.transitionTo and
the previous transition will be aborted automatically.
On Aug 6, 2014 10:02 AM, "Oliver Woodings" notifications@github.com wrote:

Yeah basically I don't want to go into a certain resource if the user
isn't authenticated since fetching the models won't work unless you are
authenticated


Reply to this email directly or view it on GitHub
#38 (comment)
.

@KidkArolis
Copy link
Contributor

I've slightly clarified the docs via @4dd29454a7ce608bfb82c943934d9f83ec98816a and added a new issue about making willTransition look more like an event #43

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

2 participants