Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react'
- import { render } from 'react-dom'
- import { browserHistory, Router, Route, IndexRoute, Link } from 'react-router'
- import { Motion, spring, TransitionMotion } from 'react-motion'
- import './app.css'
- class App extends React.Component {
- get styles() {
- return {
- '/page1': {
- opacity: spring(1)
- },
- '/page2': {
- opacity: spring(1)
- }
- }
- }
- // not used here! We don't add any new item
- willEnter(key) {
- return {
- opacity: spring(0)
- }
- }
- willLeave(key, style) {
- return {
- opacity: spring(0)
- }
- }
- render() {
- return (
- <div>
- <ul>
- <li><Link to="/page1">Page 1</Link></li>
- <li><Link to="/page2">Page 2</Link></li>
- </ul>
- <TransitionMotion
- styles={this.styles}
- willEnter={this.willEnter}
- willLeave={this.willLeave}
- >
- {interpolatedStyles => {
- return <div key={this.props.location.pathname} style={interpolatedStyles[this.props.location.pathname]}>{this.props.children}</div>
- }}
- </TransitionMotion>
- </div>
- )
- }
- }
- class Index extends React.Component {
- render() {
- return (
- <div className="Image">
- <h1>Index</h1>
- <p>Animations with React Router are not different than any other animation.</p>
- </div>
- )
- }
- }
- class Page1 extends React.Component {
- render() {
- return (
- <div className="Image">
- <h1>Page 1</h1>
- <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
- </div>
- )
- }
- }
- class Page2 extends React.Component {
- render() {
- return (
- <div className="Image">
- <h1>Page 2</h1>
- <p>Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
- </div>
- )
- }
- }
- render((
- <Router history={browserHistory}>
- <Route path="/" component={App}>
- <IndexRoute component={Index}/>
- <Route path="page1" component={Page1} />
- <Route path="page2" component={Page2} />
- </Route>
- </Router>
- ), document.getElementById('example'))
Advertisement
Add Comment
Please, Sign In to add comment