Skip to content

Commit

Permalink
fix: sidebar not display using cleanUrls: true when visit with .html …
Browse files Browse the repository at this point in the history
…suffix (#982)
  • Loading branch information
Timeless0911 committed Apr 19, 2024
1 parent 2f12415 commit 0dea4cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/shared/src/runtime-utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('test shared utils', () => {
});

test('normalizeHref', () => {
expect(normalizeHref()).toEqual('/');
expect(normalizeHref('/guide/')).toBe('/guide/index.html');
expect(normalizeHref('/guide')).toBe('/guide.html');
expect(normalizeHref('/guide/index.html')).toBe('/guide/index.html');
Expand All @@ -57,7 +58,10 @@ describe('test shared utils', () => {
'mailto:bluth@example.com',
);
expect(normalizeHref('tel:123456789')).toBe('tel:123456789');
expect(normalizeHref('/guide', true)).toBe('/guide');
expect(normalizeHref('/guide/', true)).toBe('/guide/index');
expect(normalizeHref('/guide.html', true)).toBe('/guide');
expect(normalizeHref('/guide/index.html', true)).toBe('/guide/index');
expect(normalizeHref('/guide/version-0.1')).toBe('/guide/version-0.1.html');
expect(normalizeHref('/guide/version-0.1.html')).toBe(
'/guide/version-0.1.html',
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/runtime-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ export function normalizeHref(url?: string, cleanUrls = false) {
cleanUrl += 'index';
}

if (cleanUrls && cleanUrl.endsWith('.html')) {
cleanUrl = cleanUrl.replace(/\.html$/, '');
}

return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
}

Expand Down

0 comments on commit 0dea4cb

Please sign in to comment.