fix(vue-app): set push on router instance rather than prototype (#8523)

resolves #7479
resolves #8522
This commit is contained in:
Daniel Roe 2020-12-20 11:21:20 +00:00 committed by GitHub
parent b06df71753
commit 8c8793073f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,12 +83,7 @@ const _routes = recursiveRoutes(router.routes, ' ', _components, 1)
}
}).join('\n')%>
// TODO: remove in Nuxt 3
const emptyFn = () => {}
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onComplete = emptyFn, onAbort) {
return originalPush.call(this, location, onComplete, onAbort)
}
Vue.use(Router)
@ -117,6 +112,12 @@ function decodeObj(obj) {
export function createRouter () {
const router = new Router(routerOptions)
// TODO: remove in Nuxt 3
const originalPush = router.push
router.push = function push (location, onComplete = emptyFn, onAbort) {
return originalPush.call(this, location, onComplete, onAbort)
}
const resolve = router.resolve.bind(router)
router.resolve = (to, current, append) => {
if (typeof to === 'string') {