Skip to content

Commit

Permalink
fix: remove comma when there're no pages (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist authored Nov 3, 2019
1 parent 6a0a264 commit fb036db
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions packages/saber/src/vue-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,50 +211,53 @@ export class VueRenderer {
}

this._writingRoutes = true

const pages = [...this.api.pages.values()]

const routesFromPages = pages
.map(page => {
const relativePath = slash(page.internal.relative)
const absolutePath = slash(page.internal.absolute)
const chunkNameComment = `/* webpackChunkName: "page--${
page.internal.isFile
? path
.relative(this.api.resolveCwd('pages'), absolutePath)
.replace(/[^a-z0-9_-]/gi, '-')
: page.internal.id
}" */ `
// Always give the path a resource query
const componentPath = page.internal.isFile
? `${absolutePath}?saberPage=${page.internal.id}`
: `#cache/pages/${page.internal.id}.saberpage?saberPage=${page.internal.id}`
return `{
path: ${JSON.stringify(page.permalink)},
meta: {
__relative: '${relativePath}',
__pageId: '${page.internal.id}'
},
component: function() {
${
this.api.lazy && !this.visitedRoutes.has(page.permalink)
? `return Promise.resolve({render: function(h){return h('div', {}, ['Please refresh..'])}})`
: `
return import(${chunkNameComment}${JSON.stringify(componentPath)})
`
}
}
}`
})
.join(',\n')

const redirectRoutesInBrowser = [...this.api.pages.redirectRoutes.values()]
.filter(route => route.redirectInBrowser)
.map(
route => `{ path: '${route.fromPath}', redirect: '${route.toPath}' }`
)
.join(',\n')

const routes = `
export default [
${pages
.map(page => {
const relativePath = slash(page.internal.relative)
const absolutePath = slash(page.internal.absolute)
const chunkNameComment = `/* webpackChunkName: "page--${
page.internal.isFile
? path
.relative(this.api.resolveCwd('pages'), absolutePath)
.replace(/[^a-z0-9_-]/gi, '-')
: page.internal.id
}" */ `
// Always give the path a resource query
const componentPath = page.internal.isFile
? `${absolutePath}?saberPage=${page.internal.id}`
: `#cache/pages/${page.internal.id}.saberpage?saberPage=${page.internal.id}`
return `{
path: ${JSON.stringify(page.permalink)},
meta: {
__relative: '${relativePath}',
__pageId: '${page.internal.id}'
},
component: function() {
${
this.api.lazy && !this.visitedRoutes.has(page.permalink)
? `return Promise.resolve({render: function(h){return h('div', {}, ['Please refresh..'])}})`
: `
return import(${chunkNameComment}${JSON.stringify(
componentPath
)})
`
}
}
}`
})
.join(',\n')},
${routesFromPages ? `${routesFromPages},` : ''}
${redirectRoutesInBrowser ? `${redirectRoutesInBrowser},` : ''}
// An addtional route to catch all other requests, i.e. 404 page
{
Expand Down

0 comments on commit fb036db

Please sign in to comment.