diff --git a/src/components/common/VnCardBeta.vue b/src/components/common/VnCardBeta.vue index 16fc14c2c..d2bed6257 100644 --- a/src/components/common/VnCardBeta.vue +++ b/src/components/common/VnCardBeta.vue @@ -38,23 +38,17 @@ onBeforeMount(async () => { } }); -if (props.baseUrl) { - onBeforeRouteUpdate(async (to, from) => { - if (hasRouteParam(to.params)) { - const { matched } = router.currentRoute.value; - const { name } = matched.at(-3); - if (name) { - router.push({ name, params: to.params }); - } - } - if (to.params.id !== from.params.id) { - arrayData.store.url = `${props.baseUrl}/${to.params.id}`; - await arrayData.fetch({ append: false, updateRouter: false }); - } - }); -} -function hasRouteParam(params, valueToCheck = ':addressId') { - return Object.values(params).includes(valueToCheck); +onBeforeRouteUpdate(async (to, from) => { + const id = to.params.id; + if (id !== from.params.id) await fetch(id, true); +}); + +async function fetch(id, append = false) { + const regex = /\/(\d+)/; + if (props.idInWhere) arrayData.store.filter.where = { id }; + else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`; + else arrayData.store.url = props.url.replace(regex, `/${id}`); + await arrayData.fetch({ append, updateRouter: false }); }