Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove comma when there're no pages #544

Merged
merged 1 commit into from
Nov 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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