Implement popstate event for history tracking

Fixes #190