fix(vue-app): resolve leave transition on child routes (#6803)

This commit is contained in:
Sébastien Chopin 2020-01-10 21:45:13 +01:00 committed by Pooya Parsa
parent af75aa86e1
commit c9beac3c7b

View File

@ -107,14 +107,19 @@ function mapTransitions (Components, to, from) {
const transition = componentOption(component, 'transition', to, from) || {}
return (typeof transition === 'string' ? { name: transition } : transition)
}
const tComponents = [].concat(Components)
return Components.map((Component) => {
// If leaving a child route to a parent, keep the child leave transition
while (from && from.matched.length > tComponents.length) { // eslint-disable-line no-unmodified-loop-condition
tComponents.push({})
}
return tComponents.map((Component, i) => {
// Clone original object to prevent overrides
const transitions = Object.assign({}, componentTransitions(Component))
// Combine transitions & prefer `leave` transitions of 'from' route
if (from && from.matched.length && from.matched[0].components.default) {
const fromTransitions = componentTransitions(from.matched[0].components.default)
if (from && from.matched[i] && from.matched[i].components.default) {
const fromTransitions = componentTransitions(from.matched[i].components.default)
Object.keys(fromTransitions)
.filter(key => fromTransitions[key] && key.toLowerCase().includes('leave'))
.forEach((key) => { transitions[key] = fromTransitions[key] })