Answers for "declare module '@vue/runtime-core' $router"

0

declare module '@vue/runtime-core' $router

import { createApp } from 'vue'
import { Router, createRouter } from 'vue-router'

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $router: Router
  }
}

// effectively adding the router to every component instance
const app = createApp({})
const router = createRouter()
app.config.globalProperties.$router = router

const vm = app.mount('#app')
// we can access the router from the instance
vm.$router.push('/')
Posted by: Guest on August-23-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language