From fe8e8b76cc4b5738be86ccc880f9ca285cfd2169 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:24:47 +0530 Subject: [PATCH] Nc fix(nc-gui): form redirect url issue (#9612) * fix(nc-gui): form redirect url issue * fix(nc-gui): reload page after adding form redirect url in pushState --- .../composables/useSharedFormViewStore.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/composables/useSharedFormViewStore.ts b/packages/nc-gui/composables/useSharedFormViewStore.ts index 69fcb5db23..32413b57f5 100644 --- a/packages/nc-gui/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui/composables/useSharedFormViewStore.ts @@ -395,9 +395,24 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share const pk = extractPkFromRow(newRecord, meta.value?.columns as ColumnType[]) if (pk && isValidRedirectUrl.value) { - const url = sharedFormView.value!.redirect_url!.replace('{record_id}', pk) - window.location.href = url - window.location.reload() + const redirectUrl = sharedFormView.value!.redirect_url!.replace('{record_id}', pk) + + // Create an anchor element to parse the URL + const anchor = document.createElement('a') + anchor.href = redirectUrl + + // Check if the redirect URL has the same host as the current page + const isSameHost = anchor.host === window.location.host + + if (isSameHost) { + // Use pushState for internal links + window.history.pushState({}, 'Redirect', redirectUrl) + // Reload the page + window.location.reload() + } else { + // For external links, use window.location.href + window.location.href = redirectUrl + } } else { submitted.value = true progress.value = false