0
0
Fork 0

feat: refs #6891 improve useRedirect

This commit is contained in:
Jorge Penadés 2024-05-08 12:39:48 +02:00
parent 07c67b0df2
commit 7b370e6b93
1 changed files with 5 additions and 3 deletions

View File

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