mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(vue-app): multiple named views cause invalid syntax (#5262)
This commit is contained in:
parent
ca1ecf0ee4
commit
d03a61b040
@ -3,11 +3,12 @@ import Router from 'vue-router'
|
|||||||
import { interopDefault } from './utils'<%= isTest ? '// eslint-disable-line no-unused-vars' : '' %>
|
import { interopDefault } from './utils'<%= isTest ? '// eslint-disable-line no-unused-vars' : '' %>
|
||||||
|
|
||||||
<% function recursiveRoutes(routes, tab, components, indentCount) {
|
<% function recursiveRoutes(routes, tab, components, indentCount) {
|
||||||
let res = '', resMap = ''
|
let res = ''
|
||||||
const baseIndent = tab.repeat(indentCount)
|
const baseIndent = tab.repeat(indentCount)
|
||||||
const firstIndent = '\n' + tab.repeat(indentCount + 1)
|
const firstIndent = '\n' + tab.repeat(indentCount + 1)
|
||||||
const nextIndent = ',' + firstIndent
|
const nextIndent = ',' + firstIndent
|
||||||
routes.forEach((route, i) => {
|
routes.forEach((route, i) => {
|
||||||
|
let resMap = ''
|
||||||
// If need to handle named views
|
// If need to handle named views
|
||||||
if (route.components) {
|
if (route.components) {
|
||||||
let _name = '_' + hash(route.components.default)
|
let _name = '_' + hash(route.components.default)
|
||||||
|
24
test/fixtures/named-views/nuxt.config.js
vendored
24
test/fixtures/named-views/nuxt.config.js
vendored
@ -1,30 +1,32 @@
|
|||||||
export default {
|
export default {
|
||||||
router: {
|
router: {
|
||||||
extendRoutes(routes, resolve) {
|
extendRoutes(routes, resolve) {
|
||||||
const indexIndex = routes.findIndex(route => route.name === 'index')
|
const indexRoute = routes.find(route => route.name === 'index')
|
||||||
let index = routes[indexIndex].children.findIndex(route => route.name === 'index-child-id')
|
const indexChildRoute = indexRoute.children.find(route => route.name === 'index-child-id')
|
||||||
routes[indexIndex].children[index] = {
|
|
||||||
...routes[indexIndex].children[index],
|
Object.assign(indexChildRoute, {
|
||||||
components: {
|
components: {
|
||||||
default: routes[indexIndex].children[index].component,
|
default: indexChildRoute.component,
|
||||||
left: resolve(__dirname, 'components/childLeft.vue')
|
left: resolve(__dirname, 'components/childLeft.vue')
|
||||||
},
|
},
|
||||||
chunkNames: {
|
chunkNames: {
|
||||||
left: 'components/childLeft'
|
left: 'components/childLeft'
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
index = routes.findIndex(route => route.name === 'main')
|
routes
|
||||||
routes[index] = {
|
.filter(route => ['main', 'another'].includes(route.name))
|
||||||
...routes[index],
|
.forEach((route) => {
|
||||||
|
Object.assign(route, {
|
||||||
components: {
|
components: {
|
||||||
default: routes[index].component,
|
default: route.component,
|
||||||
top: resolve(__dirname, 'components/mainTop.vue')
|
top: resolve(__dirname, 'components/mainTop.vue')
|
||||||
},
|
},
|
||||||
chunkNames: {
|
chunkNames: {
|
||||||
top: 'components/mainTop'
|
top: 'components/mainTop'
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
test/fixtures/named-views/pages/another.vue
vendored
Normal file
6
test/fixtures/named-views/pages/another.vue
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<template>
|
||||||
|
<p>
|
||||||
|
This page exists to ensure no regression on a bug. See the commit for more
|
||||||
|
details.
|
||||||
|
</p>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user