diff --git a/app/client/src/pages/AppIDE/components/PageList/PageEntity.tsx b/app/client/src/pages/AppIDE/components/PageList/PageEntity.tsx index 2d0ac0ab02..cd51b11529 100644 --- a/app/client/src/pages/AppIDE/components/PageList/PageEntity.tsx +++ b/app/client/src/pages/AppIDE/components/PageList/PageEntity.tsx @@ -23,6 +23,7 @@ import { EntityItem } from "@appsmith/ads"; import { useNameEditorState } from "IDE/hooks/useNameEditorState"; import { useValidateEntityName } from "IDE"; import { noop } from "lodash"; +import { NavigationMethod } from "utils/history"; export const PageEntity = ({ onClick, @@ -89,7 +90,14 @@ export const PageEntity = ({ toUrl: navigateToUrl, }); dispatch(toggleInOnboardingWidgetSelection(true)); - dispatch(navigateToAnotherPage(navigateToUrl)); + dispatch( + navigateToAnotherPage({ + pageURL: navigateToUrl, + state: { + invokedBy: NavigationMethod.EntityExplorer, + }, + }), + ); if (onClick) { onClick(); diff --git a/app/client/src/sagas/ActionExecution/NavigateActionSaga/index.ts b/app/client/src/sagas/ActionExecution/NavigateActionSaga/index.ts index 63b79f5704..45d1403871 100644 --- a/app/client/src/sagas/ActionExecution/NavigateActionSaga/index.ts +++ b/app/client/src/sagas/ActionExecution/NavigateActionSaga/index.ts @@ -114,6 +114,24 @@ export function* navigateToAnyPageInApplication( yield call(pushToHistory, action.payload); } +/** + * Pushes navigation state to browser history after executing page unload actions. + * + * This function handles three different variants of history.push() calls to maintain + * backward compatibility with existing code patterns: + * + * 1. String payload: Direct path navigation without query or state + * - Uses: history.push(path) + * + * 2. Payload with state but no query: Navigation with state object + * - Uses: history.push(pageURL, state) + * + * 3. Payload with query and/or state: Full navigation with all parameters + * - Uses: history.push({ pathname, search, state }) + * + * These variants exist to conform to how the code was working previously and + * ensure consistent behavior across different navigation scenarios. + */ export function* pushToHistory(payload: NavigateToAnotherPagePayload | Path) { yield put({ type: ReduxActionTypes.EXECUTE_PAGE_UNLOAD_ACTIONS, @@ -130,6 +148,12 @@ export function* pushToHistory(payload: NavigateToAnotherPagePayload | Path) { return; } + if (!payload.query && payload.state) { + history.push(payload.pageURL, payload.state); + + return; + } + const historyState: LocationDescriptor = { pathname: payload.pageURL, search: payload.query, diff --git a/app/client/src/sagas/ActionExecution/NavigateActionSaga/types.ts b/app/client/src/sagas/ActionExecution/NavigateActionSaga/types.ts index 79cb5e01a8..4c04551905 100644 --- a/app/client/src/sagas/ActionExecution/NavigateActionSaga/types.ts +++ b/app/client/src/sagas/ActionExecution/NavigateActionSaga/types.ts @@ -2,6 +2,6 @@ import type { AppsmithLocationState } from "utils/history"; export interface NavigateToAnotherPagePayload { pageURL: string; - query: string; - state: AppsmithLocationState; + query?: string; + state?: AppsmithLocationState; }