If token exists: browser back navigates to /${subdomain}

This commit is contained in:
2026-01-15 06:15:48 +03:00
parent 2c676eb153
commit 093d4279d9

View File

@@ -30,12 +30,14 @@ import SearchButton from "./components/SearchButton";
import styles from "./menu.module.css";
import NextIcon from "components/Icons/NextIcon";
import { OpeningTimesBottomSheet } from "components/CustomBottomSheet/OpeningTimesBottomSheet";
import { useState } from "react";
import { useEffect, useState } from "react";
import BackIcon from "components/Icons/BackIcon";
import { OrderTypesBottomSheet } from "components/CustomBottomSheet/OrderTypesBottomSheet";
import { useNavigate } from "react-router-dom";
function MenuPage() {
const { subdomain } = useParams();
const navigate = useNavigate();
const { isRTL } = useAppSelector((state) => state.locale);
const { orderType } = useAppSelector((state) => state.order);
const { token } = useAppSelector((state) => state.auth);
@@ -60,6 +62,27 @@ function MenuPage() {
// Automatically load restaurant taxes when restaurant data is available
useRestaurant(restaurant);
// Handle browser back button with same logic as BackButton
useEffect(() => {
if (!token || !subdomain) {
return; // No custom route needed, allow normal back navigation
}
// Add a history entry to intercept back navigation
window.history.pushState(null, "", window.location.href);
const handlePopState = () => {
// If token exists, navigate to subdomain instead of going back
navigate(`/${subdomain}`, { replace: true });
};
window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
}, [token, subdomain, navigate]);
return (
<>
<LocalStorageHandler restaurantID={restaurant?.restautantId || ""} />