fix(generator): respect options.router.trailingSlash for crawler (#7431)

This commit is contained in:
Alexander Lichter 2020-05-28 18:26:27 +02:00 committed by GitHub
parent 2e711c143b
commit c14471681c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -299,8 +299,15 @@ export default class Generator {
// If crawler activated and called from generateRoutes() // If crawler activated and called from generateRoutes()
if (this.options.generate.crawler && this.options.render.ssr) { if (this.options.generate.crawler && this.options.render.ssr) {
const possibleTrailingSlash = this.options.router.trailingSlash ? '/' : ''
parse(html).querySelectorAll('a').map((el) => { 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)) { if (href.startsWith('/') && !path.extname(href) && this.shouldGenerateRoute(href) && !this.generatedRoutes.has(href)) {
this.generatedRoutes.add(href) // add the route to the tracked list this.generatedRoutes.add(href) // add the route to the tracked list