Created
February 7, 2019 12:01
-
-
Save Gerrilicious/ab574844316db04661b1284b1c1ae466 to your computer and use it in GitHub Desktop.
React Router animation with typescript and Pose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Libraries | |
import * as React from "react"; | |
import posed, { PoseGroup } from 'react-pose'; | |
import { Route, Switch, BrowserRouter } from "react-router-dom"; | |
// Layout | |
import Layout from "./Layout"; | |
// Components | |
import Dashboard from "./components/dashboard/Dashboard"; | |
import SubComponentIndex from "./components/subcomponent/SubComponentIndex"; | |
import SubComponentAdd from "./components/subcomponent/SubComponentAdd"; | |
class App extends React.Component<any, any> { | |
public renderRoute(): any { | |
return (location: any): any => { | |
const RouteContainer = posed.div({ | |
enter: { opacity: 1, delay: 400, beforeChildren: true }, | |
exit: { opacity: 0 } | |
}); | |
return ( | |
<Layout> | |
<PoseGroup> | |
<RouteContainer key="RouteContainer"> | |
<Switch location={location.pathname}> | |
<Route key="home" exact={true} path="/" component={Home} /> | |
<Route key="subComponentIndex" exact={true} path="/subcomponent" component={SubComponentIndex}/> | |
<Route key="subComponentAdd" path="/subcomponent/add" component={SubComponentAddPage}/> | |
<Route key="notFound" component={NotFoundComponent}/> | |
</Switch> | |
</RouteContainer> | |
</PoseGroup> | |
</Layout> | |
); | |
}; | |
} | |
public render() { | |
return ( | |
<BrowserRouter> | |
<Route render={this.renderRoute()} /> | |
</BrowserRouter> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment