diff --git a/lib/app/client.js b/lib/app/client.js index 4c2d9ff978..fb0745b3d1 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -14,21 +14,25 @@ let router <%= (store ? 'let store' : '') %> function mapTransitions(Components, to, from) { - const resolveTransitions = component => (typeof component.options.transition === 'function') - ? component.options.transition(to, from) - : component.options.transition - - const resolveRoute = route => resolveTransitions(route.matched[0].components.default) - + function componentTransitions(component) { + if (!component || !component.options || !component.options.transition) { + return {} + } + if(typeof component.options.transition === 'function') { + return component.options.transition(to, from) + } + return component.options.transition + } return Components.map((Component) => { - const transitions = Object.assign({}, to ? resolveRoute(to) : resolveTransitions(Component)) - const from_transitions = from ? resolveRoute(from) : {} - // Combine transitions & prefer leave* transitions of from route - Object.keys(from_transitions).forEach(key=> { - if (from_transitions[key] && key.toLowerCase().indexOf('leave') !== -1) { - transitions[key] = from_transitions[key] - } - }) + // 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 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 }) }