diff --git a/src/components/ui/VnSearchbar.vue b/src/components/ui/VnSearchbar.vue index 25560cee03..34da7cbf58 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 }); }