Last active
August 29, 2015 14:10
-
-
Save jonjamz/d335159ca9487c8158b8 to your computer and use it in GitHub Desktop.
Track last visited route in Iron Router by wrapping Router.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
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
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.