fix: i18n breaking on switching between realtime tabs
This commit is contained in:
@@ -143,6 +143,15 @@ export function useStreamSubscriber(): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useI18nPathInfo() {
|
||||||
|
const { localePath, getRouteBaseName } = useContext() as any
|
||||||
|
|
||||||
|
return {
|
||||||
|
localePath: localePath as (x: string) => string,
|
||||||
|
getRouteBaseName: getRouteBaseName as (x?: any) => string, // Should be a route
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function useI18n() {
|
export function useI18n() {
|
||||||
const {
|
const {
|
||||||
app: { i18n },
|
app: { i18n },
|
||||||
|
|||||||
@@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { watch, ref, useRouter, useRoute } from "@nuxtjs/composition-api"
|
import { watch, ref, useRouter, useRoute } from "@nuxtjs/composition-api"
|
||||||
import { useI18n } from "~/helpers/utils/composables"
|
import { useI18n, useI18nPathInfo } from "~/helpers/utils/composables"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
const { localePath, getRouteBaseName } = useI18nPathInfo()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
@@ -44,17 +45,21 @@ const currentTab = ref<RealtimeNavTab>("websocket")
|
|||||||
|
|
||||||
// Update the router when the tab is updated
|
// Update the router when the tab is updated
|
||||||
watch(currentTab, (newTab) => {
|
watch(currentTab, (newTab) => {
|
||||||
router.push(`/realtime/${newTab}`)
|
router.push(localePath(`/realtime/${newTab}`))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Update the tab when router is upgrad
|
// Update the tab when router is upgrad
|
||||||
watch(
|
watch(
|
||||||
route,
|
route,
|
||||||
(updateRoute) => {
|
(updateRoute) => {
|
||||||
if (updateRoute.path === "/realtime") router.replace("/realtime/websocket")
|
const path = getRouteBaseName(updateRoute)
|
||||||
|
|
||||||
const destination: string | undefined =
|
if (path.endsWith("realtime")) {
|
||||||
updateRoute.path.split("/realtime/")[1]
|
router.replace(localePath(`/realtime/websocket`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const destination: string | undefined = path.split("realtime-")[1]
|
||||||
|
|
||||||
const target = REALTIME_NAVIGATION.find(
|
const target = REALTIME_NAVIGATION.find(
|
||||||
({ target }) => target === destination
|
({ target }) => target === destination
|
||||||
|
|||||||
Reference in New Issue
Block a user