Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. // has-navigated.js
  2. import { Route } from 'react-router-dom'
  3.  
  4. let _hasNavigated = false
  5.  
  6. class Tracker extends React.Component {
  7. componentWillReceiveProps(nextProps) {
  8. if (nextProps.location !== this.props.location) {
  9. _hasNavigated = true
  10. }
  11. }
  12.  
  13. render() {
  14. return null
  15. }
  16. }
  17.  
  18. export const HasNavigatedRoute = () => (
  19. <Route component={Tracker}/>
  20. )
  21.  
  22. export const hasNavigated = () => _hasNavigated
  23.  
  24. // App.js
  25. import { HasNavigatedRoute, hasNavigated } from './has-navigated'
  26.  
  27. export default () => (
  28. <div>
  29. <HasNavigatedRoute/>
  30. {hasNavigated() ? <NormalApp/> : <FirstVisitApp/>}
  31. </div>
  32. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement