fix(generator): remove trailing slash when no subFolders are used (#6362)

This commit is contained in:
Alexander Lichter 2019-10-08 10:47:13 +02:00 committed by Pooya Parsa
parent e3e8bf6150
commit f28d12c913
2 changed files with 4 additions and 3 deletions

View File

@ -243,7 +243,8 @@ export default class Generator {
fileName = path.join(route, path.sep, 'index.html') // /about -> /about/index.html
fileName = fileName === '/404/index.html' ? '/404.html' : fileName // /404 -> /404.html
} else {
fileName = route.length > 1 ? path.join(path.sep, route + '.html') : path.join(path.sep, 'index.html')
const normalizedRoute = route.replace(/\/$/, '')
fileName = route.length > 1 ? path.join(path.sep, normalizedRoute + '.html') : path.join(path.sep, 'index.html')
}
// Call hook to let user update the path & html

View File

@ -36,14 +36,14 @@ describe('generator: generate route', () => {
const generator = new Generator(nuxt)
path.join.mockClear()
const route = '/foo'
const route = '/foo/'
const payload = {}
const errors = []
const returned = await generator.generateRoute({ route, payload, errors })
expect(nuxt.server.renderRoute).toBeCalledTimes(1)
expect(nuxt.server.renderRoute).toBeCalledWith('/foo', { _generate: true, payload })
expect(nuxt.server.renderRoute).toBeCalledWith('/foo/', { _generate: true, payload })
expect(path.join).toBeCalledTimes(2)
expect(path.join).nthCalledWith(1, '[sep]', '/foo.html')
expect(path.join).nthCalledWith(2, generator.distPath, 'join([sep], /foo.html)')