Nested routes transition reset properties on model

hi everyone.

I want to build the following route:

App.Router.map(function () {
	this.resource('entries', { path: '/entries' }, function () {
		this.resource('entry', { path: '/entry/:id' }, function () {
			this.route('edit');
		});
	});
});

I’ve nested the entry route, because I want to show the complete list and the details for the selected entry at the same time.

To control my views I set some properties in the routes afterModel and willTransition functions:

App.EntryRoute -> 
  afterModel: entry.isActive=true
  willTransition: entry.isActive=false

App.EntryEditRoute -> 
  afterModel: entry.isEditing=true
  willTransition: entry.isEditing=false

If I go from one route to another or skip the middle route the properties are not reset correctly. Because of that I think willTransition is not the right function to reset the properties. Can somebody tell me how to reset the properties the right way?

I’ve made a little fiddle to help understanding: fiddle

thanks in advance

Hook it up to a view then use the willDestroy hook on the view.

http://emberjs.jsbin.com/UJeFoGu/1/edit

All the time I thought about, how to set it up in the router or in controller but not in the view :slight_smile:

Maybe my understanding of the ember router / state model isn’t enought but I thought it’s a convention to do these sort of actions in controller or router. Please correct me if I missunderstood these.

Your understanding may be correct, but I’m unaware of hook that’s always hit when you leave a view/route. If someone else is aware of one feel free to correct me.

In your route, you can overwrite the deactivate method, which is a no-op by default.

This topic was automatically closed after 3 days. New replies are no longer allowed.