fix(generator): avoid duplicate slashes for routes ending with hash (#7776)

* fix: remove duplicate slashes from crawled routes

* fixture: use trailing slash for hash

* refactor: do trailing slash sanetization after hash removal

* test: enable trailing slash for full-static fixture

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Ahad Birang 2020-07-27 13:31:24 +04:30 committed by GitHub
parent 5f7d675807
commit 298c3e3ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -297,9 +297,9 @@ export default class Generator {
parse(html).querySelectorAll('a').map((el) => { parse(html).querySelectorAll('a').map((el) => {
const sanitizedHref = (el.getAttribute('href') || '') const sanitizedHref = (el.getAttribute('href') || '')
.replace(this.options.router.base, '/') .replace(this.options.router.base, '/')
.replace(/\/+$/, '')
.split('?')[0] .split('?')[0]
.split('#')[0] .split('#')[0]
.replace(/\/+$/, '')
.trim() .trim()
const route = decodeURI(sanitizedHref + possibleTrailingSlash) const route = decodeURI(sanitizedHref + possibleTrailingSlash)

View File

@ -10,7 +10,7 @@
<NLink to="/pagination/1"> <NLink to="/pagination/1">
Pagination Pagination
</NLink> </NLink>
<NLink to="/dynamic/foo bar#hash"> <NLink to="/dynamic/foo bar/#hash">
Dynamic route 1 Dynamic route 1
</NLink> </NLink>
<NLink to="/dynamic/foo%20bar"> <NLink to="/dynamic/foo%20bar">

View File

@ -6,7 +6,8 @@ export default {
} }
}, },
router: { router: {
// base: '/test' // base: '/test',
trailingSlash: true
}, },
hooks: { hooks: {
export: { export: {