Skip to content

Commit c582a8d

Browse files
yhzx233brc-dd
andauthored
fix(theme): correctly normalize paths ending with "index" (#3544)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent 67a9964 commit c582a8d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: src/shared/shared.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export type {
1616

1717
export const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i
1818
export const APPEARANCE_KEY = 'vitepress-theme-appearance'
19-
export const HASH_RE = /#.*$/
20-
export const EXT_RE = /(index)?\.(md|html)$/
19+
20+
const HASH_RE = /#.*$/
21+
const HASH_OR_QUERY_RE = /[?#].*$/
22+
const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/
2123

2224
export const inBrowser = typeof document !== 'undefined'
2325

@@ -60,8 +62,10 @@ export function isActive(
6062
return true
6163
}
6264

63-
export function normalize(path: string): string {
64-
return decodeURI(path).replace(HASH_RE, '').replace(EXT_RE, '')
65+
function normalize(path: string): string {
66+
return decodeURI(path)
67+
.replace(HASH_OR_QUERY_RE, '')
68+
.replace(INDEX_OR_EXT_RE, '$1')
6569
}
6670

6771
export function isExternal(path: string): boolean {

0 commit comments

Comments
 (0)