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
|
|
|
|
2019-01-06 07:56:59 +00:00
|
|
|
<%= isTest ? '// @vue/component' : '' %>
|
2016-11-19 21:16:26 +00:00
|
|
|
export default {
|
2018-11-24 18:49:19 +00:00
|
|
|
name: 'Nuxt',
|
2019-01-06 07:56:59 +00:00
|
|
|
components: {
|
|
|
|
NuxtChild,
|
|
|
|
NuxtError
|
|
|
|
},
|
2018-10-24 13:46:06 +00:00
|
|
|
props: {
|
2019-01-06 07:56:59 +00:00
|
|
|
nuxtChildKey: {
|
|
|
|
type: String,
|
|
|
|
default: undefined
|
|
|
|
},
|
2018-12-20 15:50:22 +00:00
|
|
|
keepAlive: Boolean,
|
2019-01-06 07:56:59 +00:00
|
|
|
keepAliveProps: {
|
|
|
|
type: Object,
|
|
|
|
default: undefined
|
|
|
|
},
|
2018-12-20 15:50:22 +00:00
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
default: 'default'
|
|
|
|
}
|
2018-10-24 13:46:06 +00:00
|
|
|
},
|
2019-01-06 07:56:59 +00:00
|
|
|
computed: {
|
|
|
|
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)
|
|
|
|
}
|
2019-05-09 11:53:59 +00:00
|
|
|
|
2019-05-17 09:39:52 +00:00
|
|
|
const [matchedRoute] = this.$route.matched
|
|
|
|
const Component = matchedRoute && matchedRoute.components.default
|
2019-05-09 11:53:59 +00:00
|
|
|
|
2019-05-19 18:57:20 +00:00
|
|
|
if (Component && Component.options) {
|
|
|
|
const { options } = Component
|
2019-05-09 11:53:59 +00:00
|
|
|
|
2019-05-19 18:57:20 +00:00
|
|
|
if (options.key) {
|
|
|
|
return (typeof options.key === 'function' ? options.key(this.$route) : options.key)
|
2019-05-09 11:53:59 +00:00
|
|
|
}
|
2019-01-06 07:56:59 +00:00
|
|
|
}
|
2019-05-09 11:53:59 +00:00
|
|
|
|
2019-05-17 09:39:52 +00:00
|
|
|
const strict = /\/$/.test(matchedRoute.path)
|
|
|
|
return strict ? this.$route.path : this.$route.path.replace(/\/$/, '')
|
2019-01-06 07:56:59 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeCreate() {
|
|
|
|
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
|
|
|
|
},
|
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
|
|
|
})
|
2016-11-19 21:16:26 +00:00
|
|
|
}
|
|
|
|
}
|