vuejs:有没有办法在组件内部访问 router.go() ?

vuejs: Is there a way to access router.go() inside a component?

我想在组件内部调用 router.go

目前我已经设置了 window.router = router // 所以代码有效

index.js

const App = Vue.extend(require('./views/app.vue'))
router.start(App, '#app')
window.router = router // I don't want to set this global variable

navbar.vue

methods: {
        search () {
            window.router.go({
                name: 'search',
                query: { q: this.query }
            })
        }
}

我正在寻找的是 this.$router.go

navbar.vue

methods: {
        search () {
            this.$router.go({
                name: 'search',
                query: { q: this.query }
            })
        }
    }

谢谢,非常感谢您的帮助

对于vue-router2.x

this.$router.push('path')

对于vue-router1.x

this.$route.router.go('path')