Skip to content

Commit 88b0ecc

Browse files
authored
fix: fix uri decode (#257)
1 parent 6e3c19f commit 88b0ecc

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Diff for: src/components/Sidebar.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export const Sidebar: FC<{
1818
}
1919

2020
useEffect(() => {
21-
setHash(location.hash)
21+
setHash(decodeURIComponent(location.hash))
2222
const onHashChange = () => {
23-
setHash(location.hash)
23+
const decodedHash = decodeURIComponent(location.hash)
24+
setHash(decodedHash)
2425

2526
// Don't change scroll position when the hashchange is triggered click, that's bad user experience
2627
if (location.hash && !sidebarItemClicked) {
2728
const el: HTMLAnchorElement | null = document.querySelector(
28-
`.sidebar .menu_item[href="${location.hash}"]`
29+
`.sidebar .menu_item[href="${decodedHash}"]`
2930
)
3031
if (el) {
3132
if (sidebarRef.current) {

Diff for: src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const ANCHOR_ICON = `<svg xmlns="http://www.w3.org/2000/svg" aria-hidden=
1818
`
1919

2020
export function scrollToHash(hash: string) {
21-
const el = document.querySelector(hash) as HTMLDivElement
21+
const el = document.querySelector(decodeURIComponent(hash)) as HTMLDivElement
2222
if (el) {
2323
window.scrollTo({
2424
top: el.offsetTop - 60,

Diff for: test_prod/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ this is a test
66

77
some text
88

9-
### heading 3
9+
### 中文
1010

1111
some other text

0 commit comments

Comments
 (0)