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

Using this.transitionTo skips loading the model #3989

Closed
nathanpalmer opened this issue Dec 22, 2013 · 3 comments
Closed

Using this.transitionTo skips loading the model #3989

nathanpalmer opened this issue Dec 22, 2013 · 3 comments

Comments

@nathanpalmer
Copy link

I'm not sure whether this is intentional behavior but let me explain. If I use a transitionTo on a route that has dynamic segments the model method on the destination route never gets called. Essentially I'm just passing through a params with an id and I still want to load the right model.

If I refresh the page with the right URL though the model gets loaded just fine. I put together a codepen to demonstrate.

http://codepen.io/anon/pen/LsfhB

The current version will log out to the console "I'm here." If you look at IndexRoute there is a commented out transition. If that is enabled the "I'm here" never triggers.

Is this expected? If so, where should I be loading my model for the confirmation route?

@rlivsey
Copy link
Contributor

rlivsey commented Dec 22, 2013

If you change the transition to be this.transitionTo('confirm', 1); then it'll work as you expect.

IIRC if you pass primitives (string, number) to transition instead of a full model then it figures that's an ID and uses it to build the params for the call to model , but if you pass anything complex through (in this case an object) then it treats that as you having passed the model and so doesn't call the model hook.

The API docs could probably do with an example of passing IDs in instead of full models: http://emberjs.com/api/classes/Ember.Route.html#method_transitionTo

Hope that makes sense

@nathanpalmer
Copy link
Author

Makes sense now. My initial gut question after your comment was how do you pass in multiple parameters? But it looks like you just pass them in as separate arguments.

this.transitionTo('confirm.url', 1, 'the-slug-I-want');

That works well for me.

@viganella
Copy link

Question here, if you have a route with subroutes all with dynamic segment:
e.g.
this.route('organization', { path: 'organizations/:organization_id' }, function() {
this.route('project', { path: 'projects/:project_id' }, function() {
this.route('screen', { path: 'screens/:screen_id' });
});
and I am in another route e.g. auth route. When i go to this.transitionTo('organization.project.screen',
{organization_id: 'grege23-234-4c3e-96fe-234423' },
{project_id: '234234-23423-4b99-a492-234' },
{screen_id: '34534-48f4-471d-ad17-3'45 });
I see nothing, because model is not loaded.
How could you go for this one ?

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