I try to detect how the user got to the route. There are 3 cases I guess:
- The page was loaded directly by the URL
- The page was loaded by clicking on a Link
- The page was loaded by clicking on the history back or forward buttons in the browser
Is there any way to detect the 3 cases or - which would be enough for me - to detect if the user came to the route by the 2nd case ?
Why ? In my project I have a List-Layout. When I am scrolling down and clicking on a Link in this List the new Template will be rendered but the window has now a scrollTop Value because of the scrolling in the list.
I fixed this with this:
Router.configure({
onAfterAction : function () {
jQuery(window).scrollTop(0);
}
});
With this fix after every page load the page will be scrolled to the top (like its normal).
But:
When I clicked on a link in the list and then I click on the "Back" button in my Browser (history.back) the page will also be scrolled to the top (because of my fix) - without the fix the page will be automatically jump to the last position.
Because of this I need something like this:
Router.configure({
onAfterAction : function () {
var historyBack;
historyBack = CheckIfHistoryBackWasClicked();
if (!historyBack) jQuery(window).scrollTop(0);
}
});
Anyone any idea ?
Try to add a
click
event handler to your links and set ascrollToTop
session variable there:Then, do something like this: