nuxt.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Vue from 'vue'
  2. import { compile } from '../utils'
  3. import NuxtError from './nuxt-error.vue'
  4. import NuxtChild from './nuxt-child'
  5. export default {
  6. name: 'nuxt',
  7. props: {
  8. nuxtChildKey: String,
  9. keepAlive: Boolean
  10. },
  11. render(h) {
  12. // If there is some error
  13. if (this.nuxt.err) {
  14. return h('nuxt-error', {
  15. props: {
  16. error: this.nuxt.err
  17. }
  18. })
  19. }
  20. // Directly return nuxt child
  21. return h('nuxt-child', {
  22. key: this.routerViewKey,
  23. props: this.$props
  24. })
  25. },
  26. beforeCreate() {
  27. Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
  28. },
  29. computed: {
  30. routerViewKey() {
  31. // If nuxtChildKey prop is given or current route has children
  32. if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) {
  33. return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params)
  34. }
  35. const Component = this.$route.matched[0] && this.$route.matched[0].components.default
  36. if (Component && Component.options && Component.options.key) {
  37. return (typeof Component.options.key === 'function' ? Component.options.key(this.$route) : Component.options.key)
  38. }
  39. return this.$route.path
  40. }
  41. },
  42. components: {
  43. NuxtChild,
  44. NuxtError
  45. }
  46. }