diff --git a/packages/generator/src/generator.js b/packages/generator/src/generator.js index 6f2b3ab710..81b6d367f7 100644 --- a/packages/generator/src/generator.js +++ b/packages/generator/src/generator.js @@ -299,8 +299,15 @@ export default class Generator { // If crawler activated and called from generateRoutes() if (this.options.generate.crawler && this.options.render.ssr) { + const possibleTrailingSlash = this.options.router.trailingSlash ? '/' : '' parse(html).querySelectorAll('a').map((el) => { - const href = (el.getAttribute('href') || '').replace(/\/+$/, '').split('?')[0].split('#')[0].trim() + const sanitizedHref = (el.getAttribute('href') || '') + .replace(/\/+$/, '') + .split('?')[0] + .split('#')[0] + .trim() + + const href = sanitizedHref + possibleTrailingSlash if (href.startsWith('/') && !path.extname(href) && this.shouldGenerateRoute(href) && !this.generatedRoutes.has(href)) { this.generatedRoutes.add(href) // add the route to the tracked list