Search code examples
meteoriron-router

Router links with iron-router going to "random" places on the page


I am using iron-router with a meteor application. A strange thing is happening. Certain links for routes (for instance /purchase) is taking me to the middle or the bottom of the page. The behavior seems to be random. Is there any way to ensure these take you to the top of the page?


Solution

  • Tell the window to scroll top when navigated to a route:

    route: {
        name: 'name'
        template: 'template'
        onAfterAction: function () {
            scrollTop();
        }
    }
    
    function scrollTop() {
        window.scrollTo(0, 0);
    }