{"comment":{"url":"https://api.github.com/repos/EventedMind/iron-router/comments/9250950","html_url":"https://github.com/EventedMind/iron-router/commit/65b844eb0d988d93b1ac8a5bf54966d4dd2f0c46#commitcomment-9250950","id":9250950,"user":{"login":"adamgins","id":7233741,"avatar_url":"https://avatars.githubusercontent.com/u/7233741?v=3","gravatar_id":"","url":"https://api.github.com/users/adamgins","html_url":"https://github.com/adamgins","followers_url":"https://api.github.com/users/adamgins/followers","following_url":"https://api.github.com/users/adamgins/following{/other_user}","gists_url":"https://api.github.com/users/adamgins/gists{/gist_id}","starred_url":"https://api.github.com/users/adamgins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamgins/subscriptions","organizations_url":"https://api.github.com/users/adamgins/orgs","repos_url":"https://api.github.com/users/adamgins/repos","events_url":"https://api.github.com/users/adamgins/events{/privacy}","received_events_url":"https://api.github.com/users/adamgins/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"65b844eb0d988d93b1ac8a5bf54966d4dd2f0c46","created_at":"2015-01-12T23:16:26Z","updated_at":"2015-01-12T23:16:26Z","body":"I just put a check in for undefined, so now working with:\r\n\r\n```\r\nRouter.onAfterAction(function() {\r\n    var self = this;\r\n    // always start by resetting scroll to top of the page\r\n    $(window).scrollTop(0);\r\n    // if there is a hash in the URL, handle it\r\n    if (this.params.hash) {\r\n        // now this is important : Deps.afterFlush ensures that iron-router rendering\r\n        // process has finished inserting the current route template into DOM so we\r\n        // can manipulate it via jQuery, if you skip this part the HTML element you\r\n        // want to scroll to might not yet be present in the DOM (this is probably\r\n        // why your code fails in the first place)\r\n        Tracker.afterFlush(function() {\r\n\r\n            if (typeof $(\"#\" + self.params.hash).offset() != \"undefined\"){\r\n                var scrollTop = $(\"#\" + self.params.hash).offset().top;\r\n\r\n                $(\"html,body\").animate({\r\n                    scrollTop: scrollTop\r\n                });\r\n\r\n            }\r\n\r\n        });\r\n    }\r\n});\r\n```"}}