Skip to content

Commit 7c4ae21

Browse files
committed
Add support for clearing queryString in tabs
1 parent 452175a commit 7c4ae21

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

.vscode/extensions.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
2+
"recommendations": [
3+
"Vue.volar"
4+
]
35
}

src/components/Tabs.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ const props = withDefaults(defineProps<{
3535
tabClass?: string
3636
bodyClass?: string
3737
url?:boolean
38+
clearQuery?:boolean
3839
}>(), {
3940
id: 'tabs',
4041
param: 'tab',
4142
label: (tab:string) => humanize(tab),
4243
bodyClass: 'p-4',
43-
url: true
44+
url:true,
45+
clearQuery:false,
4446
})
4547
4648
const tabNames = computed(() => Object.keys(props.tabs))
@@ -55,7 +57,7 @@ function select(tab:string) {
5557
selected.value = tab
5658
if (props.url) {
5759
const firstTab = tabNames.value[0]
58-
pushState({ tab: tab === firstTab ? undefined : tab })
60+
pushState({ tab: tab === firstTab ? undefined : tab }, props.clearQuery)
5961
}
6062
}
6163

src/use/utils.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Ref } from "vue"
22
import { isRef, nextTick, unref } from "vue"
33
import type { ApiRequest, IReturn, TransitionRules } from "@/types"
4-
import { ApiResult, appendQueryString, dateFmt, enc, JsonServiceClient, nameOf, omit, setQueryString, toTime } from "@servicestack/client"
4+
import { ApiResult, appendQueryString, dateFmt, enc, JsonServiceClient, lastLeftPart, nameOf, omit, setQueryString, toTime } from "@servicestack/client"
55
import { assetsPathResolver } from "./config"
66
import { Sole } from "./config"
77

@@ -139,9 +139,11 @@ export function parseJson(json?:string|null) {
139139
return typeof json == 'string' ? JSON.parse(json) : null
140140
}
141141

142-
export function pushState(args:Record<string,any>) {
143-
if (typeof history != 'undefined') {
144-
const url = setQueryString(location.href, args)
142+
export function pushState(args:Record<string,any>, clear?:boolean) {
143+
if (typeof history != 'undefined') {
144+
const url = clear
145+
? setQueryString(location.href, args)
146+
: appendQueryString(lastLeftPart(location.href,'?'), args)
145147
history.pushState({}, '', url)
146148
}
147149
}

0 commit comments

Comments
 (0)