I have a chat application made with react and react router I used react transition group in order to animate between chats but the problem is that I have pictures in the chats and I wanted to display them to the user when he clicks on them and also wanted to do it with a route and animate it like in any chat app but the parent route which is the chat animates out.
It's like when the route changes from "/chat/:chatID"
to "/chat/:chatID/image"
it animates out I saw a lot of solutions to this but none of them worked for me and I'm really upset and angry I don't understand why react router creators didn't give us an option to animate out the component when we want.
Here's the code of chat component Route:
<TransitionGroup component={null}>
<CSSTransition
timeout={300}
classNames="page"
key={!location.pathname.includes("/image") ? location.pathname : null}
>
<Route path={`${path}/room/:roomID`} location={location}>
<chat
unreadMessages={unreadMessages}
animState={state}
imagePreview={imagePreview}
setImagePreview={setImagePreview}
/>
</Route>
</CSSTransition>
</TransitionGroup>
Here's the code of of the image preview Route which is inside chat component:
<TransitionGroup component={null}>
<CSSTransition
timeout={300}
classNames="page"
key={location.pathname}
>
<Route path={path + "/image"} location={location}>
<ImagePreview
setImagePreview={setImagePreview}
imagePreview={imagePreview}
path={path}
animState={animState}
/>
</Route>
</CSSTransition>
</TransitionGroup>
As you can see I access the location.pathname
and check if it has the image route if it does I will put the key as null But still the component animates and I can see it and It only animates out but not in I want the component to not animate when I go to /image and the image will render with animation.
Also when I exit the image preview component which is supposed to show the image to user the chat component only animate in without out animation. So please help me I'm really sick of react router!!!