mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
better mapTransitions
prevents some unhandled cases
This commit is contained in:
parent
0511e90a70
commit
e753f93f97
@ -14,21 +14,25 @@ let router
|
|||||||
<%= (store ? 'let store' : '') %>
|
<%= (store ? 'let store' : '') %>
|
||||||
|
|
||||||
function mapTransitions(Components, to, from) {
|
function mapTransitions(Components, to, from) {
|
||||||
const resolveTransitions = component => (typeof component.options.transition === 'function')
|
function componentTransitions(component) {
|
||||||
? component.options.transition(to, from)
|
if (!component || !component.options || !component.options.transition) {
|
||||||
: component.options.transition
|
return {}
|
||||||
|
}
|
||||||
const resolveRoute = route => resolveTransitions(route.matched[0].components.default)
|
if(typeof component.options.transition === 'function') {
|
||||||
|
return component.options.transition(to, from)
|
||||||
return Components.map((Component) => {
|
}
|
||||||
const transitions = Object.assign({}, to ? resolveRoute(to) : resolveTransitions(Component))
|
return component.options.transition
|
||||||
const from_transitions = from ? resolveRoute(from) : {}
|
}
|
||||||
// Combine transitions & prefer leave* transitions of from route
|
return Components.map((Component) => {
|
||||||
Object.keys(from_transitions).forEach(key=> {
|
// Clone original object to prevent overrides
|
||||||
if (from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) {
|
const transitions = Object.assign({}, componentTransitions(Component))
|
||||||
transitions[key] = from_transitions[key]
|
// Combine transitions & prefer *leave* transitions of 'from' route
|
||||||
|
if(from && from.matched.length && from.matched[0].components.default) {
|
||||||
|
const from_transitions = componentTransitions(from.matched[0].components.default)
|
||||||
|
Object.keys(from_transitions)
|
||||||
|
.filter(key => from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1)
|
||||||
|
.forEach(key => { transitions[key] = from_transitions[key] })
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return transitions
|
return transitions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user