I'm working with Framer Motion and React Router so I added location={location} in <Routes>. When I try to get location.state.from it just shows me the path that I am redirected to and not the previous path. When I remove location in <Routes> then it works properly.
App.js
<AnimatePresence exitBeforeEnter>
<Routes key={location.pathname} location={location}>
<Route element={<PublicWrapper />}>
<Route path="/login" element={<Login />} />
</Route>
<Route element={<PrivateWrapper />}>
<Route path="/tracker" element={<Tracker />} />
</Route>
</Routes>
</AnimatePresence>
Login.js
const location = useLocation();
const from = location.state?.from?.pathname;
console.log(from); // Returns '/login' even if user came from '/tracker'