Revert "If token exists: browser back navigates to /${subdomain}"
This reverts commit 093d4279d9.
This commit is contained in:
@@ -30,14 +30,12 @@ import SearchButton from "./components/SearchButton";
|
|||||||
import styles from "./menu.module.css";
|
import styles from "./menu.module.css";
|
||||||
import NextIcon from "components/Icons/NextIcon";
|
import NextIcon from "components/Icons/NextIcon";
|
||||||
import { OpeningTimesBottomSheet } from "components/CustomBottomSheet/OpeningTimesBottomSheet";
|
import { OpeningTimesBottomSheet } from "components/CustomBottomSheet/OpeningTimesBottomSheet";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import BackIcon from "components/Icons/BackIcon";
|
import BackIcon from "components/Icons/BackIcon";
|
||||||
import { OrderTypesBottomSheet } from "components/CustomBottomSheet/OrderTypesBottomSheet";
|
import { OrderTypesBottomSheet } from "components/CustomBottomSheet/OrderTypesBottomSheet";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
function MenuPage() {
|
function MenuPage() {
|
||||||
const { subdomain } = useParams();
|
const { subdomain } = useParams();
|
||||||
const navigate = useNavigate();
|
|
||||||
const { isRTL } = useAppSelector((state) => state.locale);
|
const { isRTL } = useAppSelector((state) => state.locale);
|
||||||
const { orderType } = useAppSelector((state) => state.order);
|
const { orderType } = useAppSelector((state) => state.order);
|
||||||
const { token } = useAppSelector((state) => state.auth);
|
const { token } = useAppSelector((state) => state.auth);
|
||||||
@@ -62,27 +60,6 @@ function MenuPage() {
|
|||||||
// Automatically load restaurant taxes when restaurant data is available
|
// Automatically load restaurant taxes when restaurant data is available
|
||||||
useRestaurant(restaurant);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<LocalStorageHandler restaurantID={restaurant?.restautantId || ""} />
|
<LocalStorageHandler restaurantID={restaurant?.restautantId || ""} />
|
||||||
|
|||||||
Reference in New Issue
Block a user