diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index fd6e3a9b3..412e17598 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -124,12 +124,14 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const { limit } = filter; store.hasMoreData = limit && response.data.length >= limit; - processData(response.data, { map: !!store.mapKey, append }); - if (!append && !isDialogOpened()) updateRouter && updateStateParams(); - + if (!append && !isDialogOpened() && updateRouter) { + if (updateStateParams(response.data)?.redirect) return; + } store.isLoading = false; canceller = null; + processData(response.data, { map: !!store.mapKey, append }); + return response; } @@ -259,7 +261,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { if (Object.values(store.userParams).length) await fetch({}); } - function updateStateParams() { + function updateStateParams(data) { if (!route?.path) return; const newUrl = { path: route.path, query: { ...(route.query ?? {}) } }; if (store?.searchUrl) @@ -276,15 +278,15 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const { path } = matches.at(-1); const to = - store?.data?.length === 1 - ? path.replace(/\/(list|:id)|-list/, `/${store.data[0].id}`) + data?.length === 1 + ? path.replace(/\/(list|:id)|-list/, `/${data[0].id}`) : path.replace(/:id.*/, ''); if (route.path != to) { const pushUrl = { path: to }; if (to.endsWith('/list') || to.endsWith('/')) pushUrl.query = newUrl.query; - return router.push(pushUrl); + return router.push(pushUrl) && { redirect: true }; } }