Nuxt/lib/app/components/nuxt.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import Vue from 'vue'
2016-12-16 16:45:47 +00:00
import NuxtChild from './nuxt-child'
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'
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
})
},
beforeCreate () {
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
},
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) {
return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params)
}
return this.$route.fullPath.split('#')[0]
}
},
components: {
2016-12-16 16:45:47 +00:00
NuxtChild,
NuxtError
}
}