Skip to content

Instantly share code, notes, and snippets.

@ramingar
Last active January 11, 2019 12:37
Show Gist options
  • Save ramingar/5742eace077ec5098cb9a76088934bd1 to your computer and use it in GitHub Desktop.
Save ramingar/5742eace077ec5098cb9a76088934bd1 to your computer and use it in GitHub Desktop.
Onsen+Vue PWA's backbutton management #vue #onsen #pwa #backbutton

Fuente: https://stackoverflow.com/a/49719812

Autor: https://stackoverflow.com/users/3926156/alecdwm

// App.vue

export default {
    // ...
    created() {
        window.pageStack = this.pageStack;  // pageStack global due to backbutton management in index.html (for mobile devices)
    },
    // ...
}
<!-- index.html -->
<script>
    window.addEventListener('load', function () {
        window.history.pushState({}, '')
    });
    window.addEventListener('popstate', function () {
        if (window.pageStack.length > 2) {
            window.pageStack.pop();
            window.history.pushState({}, '')
        }
    })
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment