0
0
Fork 0

feat: refs #6891 improve useRedirect

This commit is contained in:
Jorge Penadés 2024-05-08 12:06:31 +02:00
parent 1d16abd572
commit 4d1cef7f68
1 changed files with 2 additions and 7 deletions

View File

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