2018-10-24 13:46:06 +00:00
|
|
|
<%= isTest ? '// @vue/component' : '' %>
|
2016-11-21 13:14:35 +00:00
|
|
|
import Vue from 'vue'
|
2018-10-24 13:46:06 +00:00
|
|
|
import { compile } from '../utils'
|
2018-08-06 00:12:44 +00:00
|
|
|
|
|
|
|
<% if (components.ErrorPage) { %>
|
|
|
|
<% if (('~@').includes(components.ErrorPage.charAt(0))) { %>
|
|
|
|
import NuxtError from '<%= components.ErrorPage %>'
|
|
|
|
<% } else { %>
|
|
|
|
import NuxtError from '<%= "../" + components.ErrorPage %>'
|
|
|
|
<% } %>
|
|
|
|
<% } else { %>
|
|
|
|
import NuxtError from './nuxt-error.vue'
|
|
|
|
<% } %>
|
2018-10-24 13:46:06 +00:00
|
|
|
import NuxtChild from './nuxt-child'
|
2016-11-19 21:16:26 +00:00
|
|
|
|
|
|
|
export default {
|
2018-11-24 18:49:19 +00:00
|
|
|
name: 'Nuxt',
|
2018-10-24 13:46:06 +00:00
|
|
|
props: {
|
|
|
|
nuxtChildKey: String,
|
2018-12-20 15:50:22 +00:00
|
|
|
keepAlive: Boolean,
|
2018-12-23 07:43:36 +00:00
|
|
|
keepAliveProps: Object,
|
2018-12-20 15:50:22 +00:00
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
default: 'default'
|
|
|
|
}
|
2018-10-24 13:46:06 +00:00
|
|
|
},
|
2017-10-07 09:47:31 +00:00
|
|
|
render(h) {
|
|
|
|
// If there is some error
|
|
|
|
if (this.nuxt.err) {
|
2018-11-24 18:49:19 +00:00
|
|
|
return h('NuxtError', {
|
2017-10-07 09:47:31 +00:00
|
|
|
props: {
|
|
|
|
error: this.nuxt.err
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// Directly return nuxt child
|
2018-11-24 18:49:19 +00:00
|
|
|
return h('NuxtChild', {
|
2018-01-17 08:39:34 +00:00
|
|
|
key: this.routerViewKey,
|
|
|
|
props: this.$props
|
2017-10-07 09:47:31 +00:00
|
|
|
})
|
|
|
|
},
|
2018-10-24 13:46:06 +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: {
|
2018-10-24 13:46:06 +00:00
|
|
|
routerViewKey() {
|
2017-07-09 14:29:14 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|