transitionTo('route', context) passes context base route, not to the route requested
Asked Answered
D

1

5

I am working on an Ember app where I wish a button click to transition to a new route passing an object as the context for that route.

The problem is, no matter how I try and pass that context, it is always lost by the time I get to the route I am transitioning to.

Investigating (http://jsfiddle.net/fxbXM/2/) it seems that the the context is passed to the first route the router hits as it works to the requested route. (See the output of the connectOutlets function from each route level)

This seems to confirm what I thought I had found when debugging my actual app: in the triggerSetupContext function of Ember there are three enterStates: [Router, 'root', 'create'] and there are three contexts: [myObject, null, null]

If the contexts were in the opposite order then I would get what I wanted where I wanted it!

Am I making some fundamental error in the way i'm passing the object as a context? Should I be using another approach?

Delmerdelmor answered 21/8, 2012 at 21:8 Comment(0)
T
5

A bit tricky to realize what does'nt work... while debugging, I found this: in routers, only states with dynamic segments have a context, so in the create route, I added ":widget_id", and it seems to work. see http://jsfiddle.net/Sly7/EqyUa/

It seems that if you don't have any dynamic segment in your route, you can't pass a context to it. It would be great if I can have confirmation of that...

Update

Searching on github repo, I found this issue: #1118. In the last comment, Yehuda explain why this does not make sense to pass a context to connectOutlets without dynamic segment.

Trackandfield answered 21/8, 2012 at 22:29 Comment(6)
Great catch in the source, hope that's going to change before release.Delmerdelmor
Updated answer, I think this is not going to change.Trackandfield
you have added the widget_id to the path but how are you accessing that information in the router? lets say you would like to update your model using the model hook, now how to access the widget_id to update the model?Scarcity
@Scarcity Not sure for now, but I think the model hook has a parameter. (usually named params). Then you can access the widget_id with params.widget_id. Anyway this answer is no longer up to date, I will update it against RC1.Trackandfield
I did some reading and found out that, model hook in the router will receive the url parameters as a params object, I tried this but I do not see the model hook getting invoked in the router,emberjs.com/guides/routing/specifying-a-routes-modelScarcity
@Scarcity Hmm, could you post your own question with as information as possible, the best would be to have a jsfiddle or jsbin.Trackandfield

© 2022 - 2024 — McMap. All rights reserved.