fix(vue-app): multiple named views cause invalid syntax (#5262)

This commit is contained in:
Michael Leaney 2019-03-19 18:25:20 +08:00 committed by Xin Du (Clark)
parent ca1ecf0ee4
commit d03a61b040
3 changed files with 27 additions and 18 deletions

View File

@ -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)

View File

@ -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'
} }
} })
})
} }
} }
} }

View 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>