forked from verdnatura/salix-front
feat: refs #6891 improve useRedirect
This commit is contained in:
parent
1d16abd572
commit
4d1cef7f68
|
@ -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 };
|
||||
|
|
Loading…
Reference in New Issue