mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-18 03:35:17 +00:00
3f1d634fb7
* Minor consistency enhancements * Arrow parenthesis consistency * Change linting rule * Fix typo * Update .eslintrc.js to only require parens for blocks * Update style according to brace-only suggestion * Remove --fix from lint * Tweak no-loading time (failing test) * Tweak no-loading time (failing test) (2) * Tweak no-loading time (failing test) (3) * Tweak no-loading time (failing test) (4) * Tweak no-loading time (failing test) (5)
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import Vue from 'vue'
|
|
import NuxtChild from './nuxt-child'
|
|
|
|
<% 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'
|
|
<% } %>
|
|
|
|
import { compile } from '../utils'
|
|
|
|
export default {
|
|
name: 'nuxt',
|
|
props: ['nuxtChildKey', 'keepAlive'],
|
|
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,
|
|
props: this.$props
|
|
})
|
|
},
|
|
beforeCreate () {
|
|
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
|
|
},
|
|
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)
|
|
}
|
|
const Component = this.$route.matched[0] && this.$route.matched[0].components.default
|
|
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
|
|
}
|
|
},
|
|
components: {
|
|
NuxtChild,
|
|
NuxtError
|
|
}
|
|
}
|