From 7b370e6b93dd9f5311986df60df036d53a68e677 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 8 May 2024 12:39:48 +0200 Subject: [PATCH] feat: refs #6891 improve useRedirect --- src/composables/useRedirect.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/composables/useRedirect.js b/src/composables/useRedirect.js index ed9cc2c44..94ca5d0cb 100644 --- a/src/composables/useRedirect.js +++ b/src/composables/useRedirect.js @@ -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 };