mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Normalize components
This commit is contained in:
parent
224a18dea8
commit
55f907877e
@ -36,12 +36,6 @@ function loadAsyncComponents (to, ___, next) {
|
||||
Component().then(_resolve).catch(reject)
|
||||
})
|
||||
}
|
||||
if (typeof Component === 'object' && !Component.options) {
|
||||
// Updated via vue-router resolveAsyncComponents()
|
||||
Component = Vue.extend(Component)
|
||||
Component._Ctor = Component
|
||||
match.components[key] = Component
|
||||
}
|
||||
return Component
|
||||
})
|
||||
<%= (loading ? 'this.$loading.start && this.$loading.start()' : '') %>
|
||||
@ -155,6 +149,19 @@ function render (to, from, next) {
|
||||
})
|
||||
}
|
||||
|
||||
// Fix components format in matched, it's due to code-splitting of vue-router
|
||||
function normalizeComponents (to, ___) {
|
||||
flatMapComponents(to, (Component, _, match, key) => {
|
||||
if (typeof Component === 'object' && !Component.options) {
|
||||
// Updated via vue-router resolveAsyncComponents()
|
||||
Component = Vue.extend(Component)
|
||||
Component._Ctor = Component
|
||||
match.components[key] = Component
|
||||
}
|
||||
return Component
|
||||
})
|
||||
}
|
||||
|
||||
// When navigating on a different route but the same component is used, Vue.js
|
||||
// will not update the instance data, so we have to update $data ourselves
|
||||
function fixPrepatch (to, ___) {
|
||||
@ -329,6 +336,7 @@ Promise.all(resolveComponents)
|
||||
// Add router hooks
|
||||
router.beforeEach(loadAsyncComponents.bind(_app))
|
||||
router.beforeEach(render.bind(_app))
|
||||
router.afterEach(normalizeComponents)
|
||||
router.afterEach(fixPrepatch.bind(_app))
|
||||
if (NUXT.serverRendered) {
|
||||
mountApp()
|
||||
|
@ -36,7 +36,7 @@ const scrollBehavior = (to, from, savedPosition) => {
|
||||
if (to.matched.length < 2) {
|
||||
position = { x: 0, y: 0 }
|
||||
}
|
||||
else if (to.matched.some((r) => r.components.default.scrollToTop || (r.components.default.options && r.components.default.options.scrollToTop))) {
|
||||
else if (to.matched.some((r) => r.components.default.options.scrollToTop)) {
|
||||
position = { x: 0, y: 0 }
|
||||
}
|
||||
// if link has anchor, scroll to anchor by returning the selector
|
||||
|
Loading…
Reference in New Issue
Block a user