Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // LastVisitedTracker.tsx
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
export default function LastVisitedTracker() {
const location = useLocation();
useEffect(() => {
// Save path only if it's not a "special" redirect
if (!location.pathname.startsWith("/go-back")) {
const key = location.pathname
.split("/")
.filter((item) => {
return item.length > 0;
})
.slice(-2)
.join("-");
localStorage.setItem(`lastVisitedPath-${key}`, location.pathname);
localStorage.setItem("lastVisitedPath", location.pathname);
}
}, [location]);
return null;
}
|