feat: refs #6891 improve useRedirect

This commit is contained in:
Jorge Penadés 2024-05-08 13:00:54 +02:00
parent f7b6f3b9e1
commit 54de101442
1 changed files with 4 additions and 3 deletions

View File

@ -13,9 +13,10 @@ export default function useRedirect() {
const { matched: matches } = router.currentRoute.value;
const { path } = matches.at(-1);
let to = path.replace(/:id.*/, '');
if (data.length === 1) to = path.replace(/\/(list|-list|:id)/, `/${data[0].id}`);
const to =
data.length === 1
? path.replace(/\/(list|-list|:id)/, `/${data[0].id}`)
: path.replace(/:id.*/, '');
router.push({ path: to });
};