From 420d81866ce3b0652ad9b6da3ef294701383ae00 Mon Sep 17 00:00:00 2001 From: James Collins Date: Fri, 29 Sep 2023 12:53:24 +1000 Subject: [PATCH] back button detection --- resources/js/views/File.vue | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/resources/js/views/File.vue b/resources/js/views/File.vue index a753eba..86027cb 100644 --- a/resources/js/views/File.vue +++ b/resources/js/views/File.vue @@ -176,21 +176,22 @@ const handleLoad = async () => { } }; -window.onpopstate = function (event) { - alert( - "location: " + - document.location + - ", state: " + - JSON.stringify(event.state), - ); +const handlePopstate = () => { + // This function will be called when the user presses the back button + // or navigates through their history. + console.log("User has returned to the page"); + + // You can perform any necessary actions here. }; onMounted(() => { console.log("mounted"); + window.addEventListener("popstate", handlePopstate); handleLoad(); }); onUnmounted(() => { console.log("unmounted"); + window.removeEventListener("popstate", handlePopstate); });