How to use the routed .push () .replace () method in main.js or router.js files, and how to write it

that is, use router to jump outside the component. Tried many times, either it didn"t work or reported an error

Mar.23,2021

main.js:

// ...
new Vue({
  el: '-sharpapp',
  router,
  store,
  components: { App },
  template: '<App/>',
  created () {
    this.$router.push('/login')
  }
})

route.js:

// ...
const route = new Router({
    routes: [
        {path: '/'},
        {path: '/login'}
    ]
})
route.push('/login')
export default route

other.js:

import route from 'route.js'
route.push('/login')

first quote router

that you have written.

let testVueInstance = new Vue({
  el: '-sharpapp',
  router,
  store,
  VueI18n,
  template: '<App/>',
  components: {
    App
  }
})
testVueInstance.$router.push('/abc')

Save the root instance of new in main.js and use this instance to call the method.

Menu