I\'m loving RR4 and RM, there\'s already great examples for React Router V4 (https://github.com/ReactTraining/react-router/tree/v4/website/examples) but i\'m struggling to u
From the linked example we can simplify. First we create a wrapper component that will replace the <Match/>
tag and wrap it's component:
import React from 'react'
import { Match } from 'react-router'
import { TransitionMotion, spring } from 'react-motion'
const styles = {}
styles.fill = {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0
}
const MatchTransition = ({ component: Component, ...rest }) => {
const willLeave = () => ({ zIndex: 1, opacity: spring(0) })
return (
<Match {...rest} children={({ matched, ...props }) => (
<TransitionMotion
willLeave={willLeave}
styles={matched ? [ {
key: props.location.pathname,
style: { opacity: 1 },
data: props
} ] : []}
>
{interpolatedStyles => (
<div>
{interpolatedStyles.map(config => (
<div
key={config.key}
style={{ ...styles.fill, ...config.style }}
>
<Component {...config.data} />
</div>
))}
</div>
)}
</TransitionMotion>
)} />
)
}
export default MatchTransition
Then we use it like this:
<MatchTransition pattern='/here' component={About} />
<MatchTransition pattern='/there' component={Home} />