mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 02:12:36 +02:00
fix(core): prevent useBaseUrl returning /base/base when on /base (#6993)
This commit is contained in:
parent
dc95cb86ca
commit
e8800b9d49
2 changed files with 8 additions and 0 deletions
|
@ -77,6 +77,7 @@ describe('useBaseUrl', () => {
|
|||
expect(mockUseBaseUrl('/hello/foo', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/docusaurus/hello/foo',
|
||||
);
|
||||
expect(mockUseBaseUrl('/docusaurus')).toBe('/docusaurus/');
|
||||
expect(mockUseBaseUrl('/docusaurus/')).toBe('/docusaurus/');
|
||||
expect(mockUseBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
|
||||
expect(mockUseBaseUrl('#hello')).toBe('#hello');
|
||||
|
@ -143,6 +144,7 @@ describe('useBaseUrlUtils().withBaseUrl()', () => {
|
|||
expect(withBaseUrl('/hello/foo', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/docusaurus/hello/foo',
|
||||
);
|
||||
expect(withBaseUrl('/docusaurus')).toBe('/docusaurus/');
|
||||
expect(withBaseUrl('/docusaurus/')).toBe('/docusaurus/');
|
||||
expect(withBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
|
||||
expect(withBaseUrl('#hello')).toBe('#hello');
|
||||
|
|
|
@ -33,6 +33,12 @@ function addBaseUrl(
|
|||
return baseUrl + url.replace(/^\//, '');
|
||||
}
|
||||
|
||||
// /baseUrl -> /baseUrl/
|
||||
// https://github.com/facebook/docusaurus/issues/6315
|
||||
if (url === baseUrl.replace(/\/$/, '')) {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
// We should avoid adding the baseurl twice if it's already there
|
||||
const shouldAddBaseUrl = !url.startsWith(baseUrl);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue