2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-10 16:52:24 +03:00

feat: add afterNavigation callback (fix: #259)

This commit is contained in:
pimlie
2019-03-05 15:11:25 +01:00
parent 173b31d1d7
commit 97badf61cb
6 changed files with 48 additions and 7 deletions
+1 -1
View File
@@ -30,6 +30,6 @@ export default function _refresh(options = {}) {
metaInfo.changed.call(this, metaInfo, tags.addedTags, tags.removedTags)
}
return metaInfo
return { vm: this, metaInfo, tags }
}
}
+6 -1
View File
@@ -81,7 +81,12 @@ export default function createMixin(Vue, options) {
next()
})
$router.afterEach(() => $rootMeta.resume())
$router.afterEach(() => {
const { vm, metaInfo } = $rootMeta.resume()
if (metaInfo && metaInfo.afterNavigation && isFunction(metaInfo.afterNavigation)) {
metaInfo.afterNavigation.call(vm, metaInfo)
}
})
}
}
}
+11 -1
View File
@@ -1,4 +1,4 @@
import { isObject } from './typeof'
import { isObject, isFunction } from './typeof'
import {
keyName,
@@ -29,5 +29,15 @@ export default function setOptions(options) {
}
}
if (options.afterNavigation && !isFunction(options.afterNavigation)) {
console.warn(`afterNavigation should be a function, received ${typeof options.afterNavigation} instead`) // eslint-disable-line no-console
options.afterNavigation = void 0
return options
}
if (options.afterNavigation && !options.refreshOnceOnNavigation) {
options.refreshOnceOnNavigation = true
}
return options
}