fix: merge route.meta into options.meta (#4479)

[skip release]
This commit is contained in:
Clark Du 2018-12-04 12:19:05 +00:00 committed by Pooya Parsa
parent 14fe6792ae
commit 5a8e6e4bdf
4 changed files with 10 additions and 4 deletions

View File

@ -111,8 +111,8 @@ export async function getRouteData(route) {
// Send back a copy of route with meta based on Component definition
return {
...route,
meta: getMatchedComponents(route).map((Component) => {
return Component.options.meta || route.meta || {}
meta: getMatchedComponents(route).map((Component, index) => {
return { ...Component.options.meta, ...(index ? {} : route.meta) }
})
}
}

View File

@ -17,7 +17,8 @@ export default {
{
name: 'about-bis',
path: '/about-bis',
component: '~/pages/about.vue'
component: '~/pages/about.vue',
meta: { text: 'test-meta' }
},
{
path: '/redirect/about-bis',

View File

@ -1,6 +1,7 @@
<template>
<div>
<h1>About page</h1>
<h2>{{ meta[0].text }}</h2>
<NuxtLink to="/">
Home page
</NuxtLink>
@ -9,6 +10,9 @@
<script>
export default {
layout: 'custom'
layout: 'custom',
asyncData({ route }) {
return { meta: route.meta || 'empty-meta' }
}
}
</script>

View File

@ -134,6 +134,7 @@ describe('with-config', () => {
const html = window.document.body.innerHTML
expect(html).toContain('<h1>Custom layout</h1>')
expect(html).toContain('<h1>About page</h1>')
expect(html).toContain('<h2>test-meta</h2>')
})
test('/test/not-existed should return 404', async () => {