diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 027ef4344d..ff81554126 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -2228,3 +2228,32 @@ const utcDateString = (dateString) => { } } })(); + + +/** + * An IIFE that redirects to the home page when a user clicks on the back button on the 'request/finished/' page + */ + +(function() { + document.addEventListener("DOMContentLoaded", () => { + const currentPath = window.location.pathname; + + if (currentPath === "/request/finished/") { + + // Push a dummy state to create a history entry + history.pushState({ page: "dummy" }, "Dummy Page", "/request/review"); + // Replace the current state with the correct page state + history.replaceState({ page: "finished" }, "Finished Page", "/request/finished/") + + // Listen for back button click event + window.addEventListener("popstate", (event) => { + // Handle back navigation + if (!event.state || event.state.page !== "finished") { + // Redirect to home page + window.location.href = "/"; + } + }); + } + }); +})(); +