From 4d1cef7f685852eae9c223436a9149c4be40a200 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 May 2024 12:06:31 +0200 Subject: [PATCH] feat: refs #6891 improve useRedirect --- src/composables/useRedirect.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/composables/useRedirect.js b/src/composables/useRedirect.js index 786e1378b..ed9cc2c44 100644 --- a/src/composables/useRedirect.js +++ b/src/composables/useRedirect.js @@ -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 };