2016-11-21 13:14:35 +00:00
|
|
|
import Vue from 'vue'
|
2016-12-16 16:45:47 +00:00
|
|
|
import NuxtChild from './nuxt-child'
|
2017-06-29 16:36:22 +00:00
|
|
|
import NuxtError from '<%= components.ErrorPage ? ((components.ErrorPage.includes('~') || components.ErrorPage.includes('@')) ? components.ErrorPage : "../" + components.ErrorPage) : "./nuxt-error.vue" %>'
|
2017-08-01 13:34:14 +00:00
|
|
|
import { compile } from '../utils'
|
2016-11-19 21:16:26 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'nuxt',
|
2017-07-09 14:29:14 +00:00
|
|
|
props: ['nuxtChildKey'],
|
2017-10-07 09:47:31 +00:00
|
|
|
render(h) {
|
|
|
|
// If there is some error
|
|
|
|
if (this.nuxt.err) {
|
|
|
|
return h('nuxt-error', {
|
|
|
|
props: {
|
|
|
|
error: this.nuxt.err
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// Directly return nuxt child
|
|
|
|
return h('nuxt-child', {
|
|
|
|
key: this.routerViewKey
|
|
|
|
})
|
|
|
|
},
|
2016-11-21 13:14:35 +00:00
|
|
|
beforeCreate () {
|
2017-10-13 21:53:04 +00:00
|
|
|
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
|
2016-11-19 21:16:26 +00:00
|
|
|
},
|
2017-07-09 10:23:56 +00:00
|
|
|
computed: {
|
2017-07-09 14:29:14 +00:00
|
|
|
routerViewKey () {
|
|
|
|
// If nuxtChildKey prop is given or current route has children
|
|
|
|
if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) {
|
2017-08-01 13:16:23 +00:00
|
|
|
return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params)
|
2017-07-09 10:23:56 +00:00
|
|
|
}
|
2017-11-16 12:22:45 +00:00
|
|
|
const Component = this.$route.matched[0] && this.$route.matched[0].components.default
|
2017-11-06 17:29:45 +00:00
|
|
|
if (Component && Component.options && Component.options.key) {
|
|
|
|
return (typeof Component.options.key === 'function' ? Component.options.key(this.$route) : Component.options.key)
|
|
|
|
}
|
|
|
|
return this.$route.path
|
2017-07-09 10:23:56 +00:00
|
|
|
}
|
|
|
|
},
|
2016-11-19 21:16:26 +00:00
|
|
|
components: {
|
2016-12-16 16:45:47 +00:00
|
|
|
NuxtChild,
|
2017-01-30 10:20:20 +00:00
|
|
|
NuxtError
|
2016-11-19 21:16:26 +00:00
|
|
|
}
|
|
|
|
}
|