mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 14:06:59 +02:00
fix(v2): redirect plugin: use siteConfig.trailingSlash (#4988)
This commit is contained in:
parent
80b6d9728e
commit
b54ec72389
15 changed files with 443 additions and 73 deletions
|
@ -9,8 +9,8 @@ export default function applyTrailingSlash(
|
|||
path: string,
|
||||
trailingSlash: boolean | undefined,
|
||||
): string {
|
||||
// Never apply trailing slash to an anchor link
|
||||
if (path.startsWith('#')) {
|
||||
// Never apply trailing slash to an anchor link
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,13 @@ export default function applyTrailingSlash(
|
|||
|
||||
// The trailing slash should be handled before the ?search#hash !
|
||||
const [pathname] = path.split(/[#?]/);
|
||||
const newPathname = trailingSlash
|
||||
? addTrailingSlash(pathname)
|
||||
: removeTrailingSlash(pathname);
|
||||
|
||||
// Never transform '/' to ''
|
||||
const newPathname =
|
||||
pathname === '/'
|
||||
? '/'
|
||||
: trailingSlash
|
||||
? addTrailingSlash(pathname)
|
||||
: removeTrailingSlash(pathname);
|
||||
return path.replace(pathname, newPathname);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue