From 1ea0a9a6f2f2d1e61e036c3115cfd1b561ac500c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 17 Jan 2018 09:39:34 +0100 Subject: [PATCH] wip: Add keep-alive prop to and --- lib/app/components/nuxt-child.js | 15 +++++++++++---- lib/app/components/nuxt.js | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/app/components/nuxt-child.js b/lib/app/components/nuxt-child.js index 52b5c2a78b..6181d709df 100644 --- a/lib/app/components/nuxt-child.js +++ b/lib/app/components/nuxt-child.js @@ -1,7 +1,8 @@ export default { name: 'nuxt-child', functional: true, - render (h, { parent, data }) { + props: ['keepAlive'], + render (h, { parent, data, props }) { data.nuxtChild = true const _parent = parent const transitions = parent.$nuxt.nuxt.transitions @@ -29,12 +30,18 @@ export default { } }) + let routerView = [ + h('router-view', data) + ] + if (typeof props.keepAlive !== 'undefined') { + routerView = [ + h('keep-alive', routerView) + ] + } return h('transition', { props: transitionProps, on: listeners - }, [ - h('router-view', data) - ]) + }, routerView) } } diff --git a/lib/app/components/nuxt.js b/lib/app/components/nuxt.js index d6eee5c000..a5f6879364 100644 --- a/lib/app/components/nuxt.js +++ b/lib/app/components/nuxt.js @@ -5,7 +5,7 @@ import { compile } from '../utils' export default { name: 'nuxt', - props: ['nuxtChildKey'], + props: ['nuxtChildKey', 'keepAlive'], render(h) { // If there is some error if (this.nuxt.err) { @@ -17,7 +17,8 @@ export default { } // Directly return nuxt child return h('nuxt-child', { - key: this.routerViewKey + key: this.routerViewKey, + props: this.$props }) }, beforeCreate () {