Search code examples
reactjsflow-router

How to add page transitions to React without using the router?


I tried to add page transitions to my app using ReactCSSTransitionGroup but it did not work. For some pages it worked but for some it did not. Many examples out there show how to do it with the React router. But since I use Meteor, I use a different router (FlowRouter).

Here's my render method :

render() {
  return (
    <div>
      {this.props.content()}
    </div>
  );
}

Here's how I tried to add transitions :

<ReactCSSTransitionGroup
  transitionName="pageTransition"
  transitionEnterTimeout={500}
  transitionLeaveTimeout={300}
  transitionAppear={true}
  transitionAppearTimeout={500}
>
  {/* Content */}
  {React.cloneElement(this.props.content(), {
    key: uuid.v1(),
  })}

</ReactCSSTransitionGroup>

The css :

//Page transition
.pageTransition-enter {
  opacity: 0.01;
}
.pageTransition-enter.pageTransition-enter-active {
  animation: fadeIn 1s ease-in;
}
.animation-leave {
  opacity: 1;
}
.pageTransition-leave.pageTransition-leave-active {
  animation: fadeIn 3s ease-in;
}
.pageTransition-appear {
  opacity: 0.01;
}
.pageTransition-appear.pageTransition-appear-active {
  animation: opacity 5s ease-in;
}

Any idea how to make this work?


Solution

  • I figured it out! Your CSS animations are trying to use fadeIn, but that's not a CSS property. You need to change it to opacity. Like so:

    //Page transition
    .pageTransition-enter {
      opacity: 0.01;
    }
    .pageTransition-enter.pageTransition-enter-active {
      animation: opacity 1s ease-in;
    }
    .animation-leave {
      opacity: 1;
    }
    .pageTransition-leave.pageTransition-leave-active {
      animation: opacity 3s ease-in;
    }
    .pageTransition-appear {
      opacity: 0.01;
    }
    .pageTransition-appear.pageTransition-appear-active {
      animation: opacity 5s ease-in;
    }