diff --git a/packages/generator/src/generator.js b/packages/generator/src/generator.js index de974e653a..53448b8ede 100644 --- a/packages/generator/src/generator.js +++ b/packages/generator/src/generator.js @@ -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 diff --git a/packages/generator/test/generator.route.test.js b/packages/generator/test/generator.route.test.js index aaa877892b..a44074ac3b 100644 --- a/packages/generator/test/generator.route.test.js +++ b/packages/generator/test/generator.route.test.js @@ -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)')