I have a route defined as following:
<Route path={`list`} element={<ListPage />}>
<Route path={`sidePanel1`} element={<SidePanel1 />} />
<Route path={`sidePanel2`} element={<SidePanel2 />} />
<Route index element={<Navigate to={`sidePanel1`} replace />}/>
</Route>
So, when /list is typed it will be redirected to /list/sidePanel1.
in the ListPage component I have this:
const ListPage = (): JSX.Element => {
const [data, setData] = useState<ListDto[]>([]);
const location = useLocation();
useEffect(() => {
getList()
.then(response => {
setData(response.data);
})
.catch(() => {
setIsLoading(false);
});
}, [location]);
return (
<ListTable data={data}/>
<SidePanelStyles>
<Outlet />
</SidePanelStyles>
);
};
So, my problem is that whenever I type /list/ the useEffect will trigger since the location has changed, and then it will trigger for the second time when redirected to /list/sidePanel1.
I want it to only be triggered after I get redirected.
How can I solve this ?