m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

Vue-router programmatic navigation #82

Open erleiuat opened 5 years ago

erleiuat commented 5 years ago

I'm using programmatic navigation at some parts of my app, for example this.$router.go(-1) from the toolbar and with the backbutton callback from cordova.

While normal navigation with router.push({name: 'xyz'}) is working properly, navigating back doesn't seem to work (same when modifying the history directly). Now I don't know if this issue is directly related to the plugin, but I couldn't find similar issues somewhere else. So if someone knows where this belongs instead, I'd be grateful to know.

My router config is set to hash mode as it should be and this is my vue.config.js for cordova:

module.exports = {
    publicPath: '',

    pluginOptions: {
        cordovaPath: 'src-cordova'
    }
}

As far as I observed the window.history is being modified successful when navigating back. But there is no navigation being done by vue-router itself therefore the view won't be changed.

erleiuat commented 5 years ago

Example using 'backbutton' callback:

if (process.env.CORDOVA_PLATFORM) {
    document.addEventListener('backbutton', () => {
        this.$router.go(-1)
     }, false)
}

Router Config:

const router = new Router({
    mode: process.env.CORDOVA_PLATFORM ? "hash" : "history",
    base: process.env.BASE_URL,
    scrollBehavior (to, from, savedPosition) {
        return { x: 0, y: 0 }
    },
    routes: [
        ...main,
        ...auth,
        ...app,
        ...premium
    ]
})
vesper8 commented 4 years ago

@erleiuat did you manage to solve this ?