is there way use es6 extend
feature react-router "withrouter" component?
something this:
import { withrouter } 'react-router'; export default class extends withrouter { ... //use react router history prop navigate page. handlesomeevent() { this.props.router.goback(); } ... }
or stuck using old composition pattern?
var mycomponent = react.createclass({ ... }); export default withrouter(mycomponent);
yes, it's easy, see bellow (not saying should redirect 2s after component mounted... example).
btw version of react-router 2.6 (2.4+ required withrouter)
import react, { component } 'react'; import { withrouter } 'react-router'; class mycomponent extends component { componentdidmount() { settimeout(() => { this.props.router.push('my-url') }, 2000); } render() { return ( <div>my component</div> ); } } export default withrouter(mycomponent);
Comments
Post a Comment