react-router-component
react-router-component copied to clipboard
Animated transitions possible with back/forward buttons?
Hello,
The router component has been a great help to me, but I've run into an issue that I'm not sure can be solved.
I have transitions between locations using the AnimatedLocations component, and they work great when clicking a link made with the Link component.
However, I'd also like the transitions to occur when the user uses the back/forward buttons.
Is this possible, perhaps (though I've tried and failed) by overriding the popstate or hashchange methods to manually load a location using react-router-component?
Thanks so much for your hard work on a great tool.
Have you seen this project? https://github.com/andreypopp/react-router-page-transition
@STRML Yes, I saw that project and based my app's transitions on it. However, the native back and forward buttons don't trigger the animations for me. They also don't trigger the transitions in the http://andreypopp.github.io/react-router-page-transition/ example. Thanks for your prompt response!
Yes - that code allows for a separate popState transition as animations on back/forward can get annoying. It is actually quite nice since you can set separate transitions on Link
s.
Using the code from the project, you can set the transitions on back/forward by specifying a popStateTransitionName
:
<AnimatedLocations hash className="Main" transitionName="moveUp" popStateTransitionName="moveUp">
<Location path="/" handler={MainPage} />
<Location path="/about" handler={AboutPage} />
</AnimatedLocations>
Hey guys!
I too have been trying to get this working, but I have a doubt, the -enter
transition works fine, but can someone explain to me how the -leave
transition works? For me, the page that is coming in animates, but the page leaving just vanishes.
This is my CSS:
.moveUp-enter {
-webkit-transform: translate3d(0,5%,0);
transition: all .4s;
opacity: 0.01;
}
.moveUp-enter.moveUp-enter-active {
-webkit-transform: translate3d(0,0,0);
opacity: 1;
}
.moveUp-leave {
transition: all 4s;
-webkit-transform: translate3d(0,0,0);
}
.moveUp-leave.moveUp-leave-active {
-webkit-transform: translate3d(0,-105%,0);
opacity: .01;
}
The 4s is for debugging purpose.
Looks like you're missing the full set of rules from styles.css, especially the opacity
bit.
There is more information in the React Docs for how this animation group works. Basically both elements are present in the DOM until React sees a transitionend
event, then it is finally removed.
I also tried with the exact same css on that file.
I read the docs throughly, but when happens is the -leave
just happens in a flash.
@STRML thanks so much for the explanation of the popStateTransitionName prop. It worked like a charm.
@jenil27 Have you made sure that the -leave
page isn't still in the DOM and just getting moved out of view? Your problem sounds very similar to an issue I had in which I thought the -leave
page was disappearing (happened instantly even with long transition), but it in fact was not properly positioned (absolute) and was being pushed out of view by the -enter
page element.
@dbmzzo The page isn't in the DOM, it just goes out of the DOM within a few milliseconds when another page is entering. I have positioned the pages absolutely and copied the same animations from the styles.css. Still no luck :(
Here is a GIF showing the effect:
@jenil27 any updates on your luck? Did you get this working if so how?
Nope, didn't figure it out. Gave up.