From 944bf801b78cc78fb7d771045ee51e2120e36353 Mon Sep 17 00:00:00 2001 From: zuofenghua <11100776@bbktel.com> Date: Fri, 23 Oct 2020 20:59:30 +0800 Subject: [PATCH] fix: switch language bug. #106 --- src/client/theme-default/components/NavBarLinks.ts | 10 ++++------ src/shared/config.ts | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/client/theme-default/components/NavBarLinks.ts b/src/client/theme-default/components/NavBarLinks.ts index 413aab4d..85510f26 100644 --- a/src/client/theme-default/components/NavBarLinks.ts +++ b/src/client/theme-default/components/NavBarLinks.ts @@ -88,13 +88,11 @@ export default { } }) + const navData = computed(() => { + return siteDataByRoute.value.themeConfig.nav + }) return { - navData: - process.env.NODE_ENV === 'production' - ? // navbar items do not change in production - siteDataByRoute.value.themeConfig.nav - : // use computed in dev for hot reload - computed(() => siteDataByRoute.value.themeConfig.nav), + navData, repoInfo, localeCandidates } diff --git a/src/shared/config.ts b/src/shared/config.ts index 2480f751..2d883c58 100644 --- a/src/shared/config.ts +++ b/src/shared/config.ts @@ -1,4 +1,5 @@ import { SiteData } from '../../types/shared' +const inBrowser = typeof window !== 'undefined' function findMatchRoot(route: string, roots: string[]) { // first match to the routes with the most deep level. @@ -27,6 +28,12 @@ function resolveLocales( // this merges the locales data to the main data by the route export function resolveSiteDataByRoute(siteData: SiteData, route: string) { + if (inBrowser) { + const siteBaseWithoutSuffix = siteData.base.endsWith('/') + ? siteData.base.slice(0, -1) + : siteData.base + route = route.slice(siteBaseWithoutSuffix.length) + } const localeData = resolveLocales(siteData.locales || {}, route) || {} const localeThemeConfig = resolveLocales(