i using react router. want detect previous page (within same app) coming from. have router in context. but, don't see properties "previous path" or history on router object. how do it?
you can save previous path in componentwillreceiveprops
lifecycle method. logic close example provided in troubleshooting section of react-router
docs.
<route component={app}> {/* ... other routes */} </route> const app = react.createclass({ getinitialstate() { return { prevpath: '' } }, componentwillreceiveprops(nextprops) { if (nextprops.location !== this.props.location) { this.setstate({ prevpath: this.props.location }) } } })
and lately, access state.
Comments
Post a Comment