Skip to content

Instantly share code, notes, and snippets.

@jonjamz
Last active August 29, 2015 14:10
Show Gist options
  • Save jonjamz/d335159ca9487c8158b8 to your computer and use it in GitHub Desktop.
Save jonjamz/d335159ca9487c8158b8 to your computer and use it in GitHub Desktop.
Track last visited route in Iron Router by wrapping Router.go
var go;
go = Router.go;
Session.set('lastRoute', null);
Router.go = function() {
if (!Session.equals('lastRoute', Router.current().route.path())) {
Session.set('lastRoute', Router.current().route.path());
}
return go.apply(this, arguments);
};
// Check if a user has visited any route with History API by checking for Session.equals('lastRoute', null);
@jperl
Copy link

jperl commented Jan 6, 2015

Hey thanks for this, it's very interesting. One issue is that it will not handle when the user presses the back or forward button.

@jperl
Copy link

jperl commented Jan 6, 2015

Here is another potential solution I just came up with it will track route changes from the back and forward buttons. https://gist.github.com/jperl/d4d505005549165ab1d9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment