Curtis Larson's Blog    Main Site    Portfolio     Archive     Feed

Meteor - iron:router Scroll to Top


I use the awesome iron:router package in all my Meteor projects. One problem I run into in almost all packages is if you use Router.go() while scrolled down onto the page, your next page will rendered still scrolled at the same point. Here is some code that will fix that and scroll to the top of the page on each route.

The Code

We are just going to use a simple autorun function that depends on the reactive Router.current() object. Check out the code below

That’s it! Very simple, but something I always include in my boilerplate code when I first create an application. Make sure to leave any questions or comments you have.

Curtis Larson is a LA based freelance software developer. Follow him on Twitter or send him an email if you're looking for a talented developer.