So here’s a kicker. It seems as I am moving between routes in my app I am seeing the scroll position of one route is causing the scroll position of the next route to be set scrolled down the new route. Which is not what I want.
I get that if I’m transitioning from say items
to an item
and then I go back, either by hitting back, or transitioning to the items
route I want the scroll position to go back, which as far as I can tell is working out of the box. However, the situation first stated where unrelated routes are passing scroll position back and forth is unwanted.
So a quick google search turned up an old cookbook
entry in the docs to a short mixin
activate: function() {
this._super();
Ember.$('.content').scrollTop(0);
}
And injecting this mixin into routes resets the scroll position. But, something came up as I was implementing this and I saw where now I’m forcing returns to the previous route (in a parent, child route situation) was now not working how the end user will expect.
Has anyone come across a situation like this and has a solution for it?
My thought is to create a service that just stores the previous route, that service will get updated on willTransition
so that at any point I can see what the previous route was, and in my mixin, just check what the new route will be (items
) and if the previous route was item
then DON’T reset scroll, otherwise assume I’m arriving at items
from a route other than the child route item
and don’t reset scroll.
By the way, my router looks like this
this.route('items');
this.route('item',{path:'items/:item_id'});
Because I don’t want the item embedded in the parent route in this particular situation. Not sure if that is my point of conflict here or not.