fix(theme): keep hash same when switching locales

pull/2249/head
Divyansh Singh 2 years ago
parent 1517cdfc18
commit c1e502b590

@ -0,0 +1,12 @@
import { inBrowser } from '../../shared'
import { ref } from 'vue'
const hashRef = ref(inBrowser ? location.hash : '')
if (inBrowser) {
window.addEventListener('hashchange', () => {
hashRef.value = location.hash
})
}
export { hashRef }

@ -1,6 +1,7 @@
import { computed } from 'vue'
import { useData } from './data'
import { ensureStartingSlash } from '../support/utils'
import { useData } from './data'
import { hashRef } from './hash'
export function useLangs({
removeCurrent = true,
@ -20,12 +21,15 @@ export function useLangs({
? []
: {
text: value.label,
link: normalizeLink(
value.link || (key === 'root' ? '/' : `/${key}/`),
theme.value.i18nRouting !== false && correspondingLink,
page.value.relativePath.slice(currentLang.value.link.length - 1),
!site.value.cleanUrls
)
link:
normalizeLink(
value.link || (key === 'root' ? '/' : `/${key}/`),
theme.value.i18nRouting !== false && correspondingLink,
page.value.relativePath.slice(
currentLang.value.link.length - 1
),
!site.value.cleanUrls
) + hashRef.value
}
)
)

@ -11,13 +11,14 @@ import {
type ComputedRef,
type Ref
} from 'vue'
import { inBrowser, isActive } from '../../shared'
import { isActive } from '../../shared'
import {
hasActiveLink as containsActiveLink,
getSidebar,
getSidebarGroups
} from '../support/sidebar'
import { useData } from './data'
import { hashRef } from './hash'
export interface SidebarControl {
collapsed: Ref<boolean>
@ -134,13 +135,6 @@ export function useCloseSidebarOnEscape(
}
}
const hashRef = ref(inBrowser ? location.hash : '')
if (inBrowser) {
window.addEventListener('hashchange', () => {
hashRef.value = location.hash
})
}
export function useSidebarControl(
item: ComputedRef<DefaultTheme.SidebarItem>
): SidebarControl {

Loading…
Cancel
Save