1.0.1 • Published 8 years ago
react-router-deferred-route v1.0.1
react-router-deferred-route
Simple way to defer unmount your route component
Instalation
npm install react-router-deferred-route --saveUsage example
add a nice animation of the disappearance
import DeferredRoute from 'react-router-deferred-route';
//...
render(){
//...
return (
<DeferredRoute
path="/target"
component={MyAwesomeComponent}
delay={300}
innerProps={{ style: { transform: 'scale(1)', transition: 'transform .3s linear' }}}
onUnmounting={{ style: { transform: 'scale(0)', transition: 'transform .3s linear' }}}
/>
)
}
//...Explanation
DeferredRoute always returns Route component (from react-router), so you can use it with Switch. But when path in DeferredRoute becomes not equal with router.route.location.pathname (current url), Route returned without any path property, so that stay will exist for delay time. After delay path will be returned to Route and that will disappear probably. As a bonus you can set onUnmounting property, to be added in props to the component only when target path and the current path is not equal.
component get
Routepropertiesworks with
react-routerv4
API
DeferredRoute.propTypes = {
component: PropTypes.func.isRequired,
path: PropTypes.string,
delay: PropTypes.number,
innerProps: PropTypes.object,
onUnmounting: PropTypes.object,
};
DeferredRoute.defaultProps = {
path: '/',
delay: 1000,
innerProps: null,
onUnmounting: null,
};