-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redirect instead of showing siblings of child
- Loading branch information
1 parent
936a221
commit 83fc18e
Showing
2 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Redirect } from 'react-router-dom'; | ||
|
||
class RedirectView extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
redirect: false, | ||
}; | ||
console.log('topicsView'); | ||
} | ||
static propTypes = { | ||
content: PropTypes.shape({ | ||
title: PropTypes.string, | ||
|
||
description: PropTypes.string, | ||
|
||
items: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
url: PropTypes.string, | ||
image: PropTypes.object, | ||
image_caption: PropTypes.string, | ||
'@type': PropTypes.string, | ||
}), | ||
), | ||
}).isRequired, | ||
}; | ||
|
||
componentDidMount() { | ||
const mainItem = this.props.content.items[0]; | ||
const mainUrl = mainItem && mainItem.url; | ||
console.log('mainitem,mainurl', mainItem, mainUrl); | ||
if (__CLIENT__ && mainUrl && window) { | ||
this.setState({ redirect: mainUrl }); | ||
} else { | ||
this.setState({ redirect: false }); | ||
} | ||
} | ||
|
||
render() { | ||
console.log('redirect state', this.state.redirect); | ||
if (this.state.redirect) { | ||
return <Redirect to={{ pathname: this.state.redirect }} />; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} | ||
|
||
export default RedirectView; |
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