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

@ -11,13 +11,14 @@ import {
type ComputedRef, type ComputedRef,
type Ref type Ref
} from 'vue' } from 'vue'
import { inBrowser, isActive } from '../../shared' import { isActive } from '../../shared'
import { import {
hasActiveLink as containsActiveLink, hasActiveLink as containsActiveLink,
getSidebar, getSidebar,
getSidebarGroups getSidebarGroups
} from '../support/sidebar' } from '../support/sidebar'
import { useData } from './data' import { useData } from './data'
import { hashRef } from './hash'
export interface SidebarControl { export interface SidebarControl {
collapsed: Ref<boolean> 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( export function useSidebarControl(
item: ComputedRef<DefaultTheme.SidebarItem> item: ComputedRef<DefaultTheme.SidebarItem>
): SidebarControl { ): SidebarControl {

Loading…
Cancel
Save