mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-28 00:22:05 +00:00
825d0e4c82
The vue-router component can have a 'key' property which means it's easier to configure transitions between routes with slugs. With this change in a layout template you can use ```html <nuxt :routerViewKey="routerViewKey" /> ``` And the following for example ```js computed: { routerViewKey () { if (this.$route.name === 'service') { return this.$route.name } else { return this.$route.fullPath } } } ``` This would implement the functionality that @myst729 mentioned here https://github.com/vuejs/vue-router/issues/474 for vue-router - some routes can just switch, but some you may want to transition as though it's a complete new page to an end-user This is a possible resolution to issue raised here https://github.com/nuxt/nuxt.js/issues/1021
55 lines
1.5 KiB
Vue
55 lines
1.5 KiB
Vue
<template>
|
|
<nuxt-error v-if="nuxt.err" :error="nuxt.err"></nuxt-error>
|
|
<nuxt-child :key="routerViewKey" v-else></nuxt-child>
|
|
</template>
|
|
|
|
<script>
|
|
import Vue from 'vue'
|
|
import NuxtChild from './nuxt-child'
|
|
import NuxtError from '<%= components.ErrorPage ? ((components.ErrorPage.includes('~') || components.ErrorPage.includes('@')) ? components.ErrorPage : "../" + components.ErrorPage) : "./nuxt-error.vue" %>'
|
|
|
|
export default {
|
|
name: 'nuxt',
|
|
props: ['routerViewKey'],
|
|
beforeCreate () {
|
|
Vue.util.defineReactive(this, 'nuxt', this.$root.$options._nuxt)
|
|
},
|
|
created () {
|
|
// Add this.$nuxt in child instances
|
|
Vue.prototype.$nuxt = this
|
|
// Add this.$root.$nuxt
|
|
this.$root.$nuxt = this
|
|
// Bind $nuxt.setLayout(layout) to $root.setLayout
|
|
this.setLayout = this.$root.setLayout.bind(this.$root)
|
|
// add to window so we can listen when ready
|
|
if (typeof window !== 'undefined') {
|
|
window.$nuxt = this
|
|
}
|
|
// Add $nuxt.error()
|
|
this.error = this.$root.error
|
|
},
|
|
<% if (loading) { %>
|
|
mounted () {
|
|
if (this.$root.$loading && this.$root.$loading.start) {
|
|
this.$loading = this.$root.$loading
|
|
}
|
|
},
|
|
watch: {
|
|
'nuxt.err': 'errorChanged'
|
|
},
|
|
methods: {
|
|
errorChanged () {
|
|
if (this.nuxt.err && this.$loading) {
|
|
if (this.$loading.fail) this.$loading.fail()
|
|
if (this.$loading.finish) this.$loading.finish()
|
|
}
|
|
}
|
|
},
|
|
<% } %>
|
|
components: {
|
|
NuxtChild,
|
|
NuxtError
|
|
}
|
|
}
|
|
</script>
|