fix: page transition played when switching collection after soft navigation

This commit is contained in:
Sonny
2024-11-09 17:16:35 +01:00
committed by Sonny
parent 81f4cd7f87
commit 9250e5f0b4
2 changed files with 19 additions and 4 deletions

View File

@@ -33,18 +33,23 @@ export default function BaseLayout({ children }: { children: ReactNode }) {
const currentLocation = new URL(window.location.href);
flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS);
router.on(
const removeStartEventListener = router.on(
'start',
(event) =>
canTransition(currentLocation, event.detail.visit.url) &&
flipClass(TRANSITION_OUT_CLASS, TRANSITION_IN_CLASS)
);
router.on(
const removefinishEventListener = router.on(
'finish',
(event) =>
canTransition(currentLocation, event.detail.visit.url) &&
flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS)
);
return () => {
removeStartEventListener();
removefinishEventListener();
};
}, []);
return (