Skip to content

Commit

Permalink
fix(console): fix url breaking when switch page
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 11, 2022
1 parent 76bee6f commit 437d160
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
7 changes: 0 additions & 7 deletions plugins/frontend/console/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ export const extensions = reactive<Record<string, Context>>({})

export const routes: Ref<RouteRecordNormalized[]> = ref([])

export const queries = reactive({})

router.afterEach(() => {
const { path, query } = router.currentRoute.value
queries[path] = query
})

interface DisposableExtension extends PageExtension {
ctx: Context
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/frontend/console/client/layout/sidebar-item.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<router-link class="k-menu-item" :to="{ path: route.path, query: queries[route.path] }">
<router-link class="k-menu-item" :to="target">
<k-icon :name="route.meta.icon || 'application'"/>
{{ route.name }}
<span class="badge" v-if="badge">{{ badge }}</span>
Expand All @@ -10,12 +10,16 @@
import { computed, PropType } from 'vue'
import { RouteRecordNormalized } from 'vue-router'
import { queries } from '../client'
import { routeCache } from './utils'
const props = defineProps({
route: {} as PropType<RouteRecordNormalized>,
})
const target = computed(() => {
return routeCache[props.route.name] || props.route.path.replace(/:.+/, '')
})
const badge = computed(() => {
return props.route.meta.badge.reduce((prev, curr) => prev + curr(), 0)
})
Expand Down
10 changes: 10 additions & 0 deletions plugins/frontend/console/client/layout/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { reactive } from 'vue'
import { RouteRecordName } from 'vue-router'
import { router } from '../client'

export const routeCache = reactive<Record<RouteRecordName, string>>({})

router.afterEach(() => {
const { name, fullPath } = router.currentRoute.value
routeCache[name] = fullPath
})
2 changes: 1 addition & 1 deletion plugins/frontend/manager/client/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import PluginSelect from './select.vue'
import PluginSettings from './settings.vue'
function join(source: string | string[]) {
return Array.isArray(source) ? source.join('/') : source
return Array.isArray(source) ? source.join('/') : source || ''
}
const route = useRoute()
Expand Down

0 comments on commit 437d160

Please sign in to comment.