mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 17:43:59 +00:00
b1b9e0bcbc
* support named views for extendRoutes config * fix lint errors * fix lint errors 2 * some refactoring * var rename * fixture & unit tests * fix: style * nuxt-child named view example and test * nuxt element with named view in layout * lint
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
<%= isTest ? '// @vue/component' : '' %>
|
|
import Vue from 'vue'
|
|
import { compile } from '../utils'
|
|
|
|
<% 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 NuxtChild from './nuxt-child'
|
|
|
|
export default {
|
|
name: 'Nuxt',
|
|
props: {
|
|
nuxtChildKey: String,
|
|
keepAlive: Boolean,
|
|
name: {
|
|
type: String,
|
|
default: 'default'
|
|
}
|
|
},
|
|
render(h) {
|
|
// If there is some error
|
|
if (this.nuxt.err) {
|
|
return h('NuxtError', {
|
|
props: {
|
|
error: this.nuxt.err
|
|
}
|
|
})
|
|
}
|
|
// Directly return nuxt child
|
|
return h('NuxtChild', {
|
|
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
|
|
}
|
|
}
|