From a0dcd6aee165a70e5412e7341c2ee6dd46dd1da0 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 26 Mar 2024 09:11:53 +0100 Subject: [PATCH] feat: refs #6893 replace id & redirect to Card or list --- src/components/ui/VnSearchbar.vue | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 25560cee0..34da7cbf5 100644 --- a/src/components/ui/VnSearchbar.vue +++ b/src/components/ui/VnSearchbar.vue @@ -97,12 +97,18 @@ async function search() { const { matched: matches } = currentRoute.value; const { path } = matches.at(-1); + const [, moduleName] = path.split('/'); - let targetUrl = path.replace(':id', searchText.value); - if (path.endsWith('/list') && store.data.length === 1) - targetUrl = targetUrl.replace('/list', `/${store.data[0].id}/summary`); + if (!store.data.length || store.data.length > 1) + return push({ path: `/${moduleName}/list` }); - await push(targetUrl); + const targetId = store.data[0].id; + let targetUrl; + + if (path.endsWith('/list')) targetUrl = path.replace('/list', `/${targetId}/summary`); + else if (path.includes(':id')) targetUrl = path.replace(':id', targetId); + + await push({ path: targetUrl }); }