I am trying to update a background image based on various routing options. However no background is displayed at all.
I've tried inline styling and making sure I'm referring to the right directories.
Originally the css just set the background by changing the html background but I could not make this dynamic.
class App extends Component {
constructor() {
super();
this.state = {
'route': 'Home'
}
}
onRouteChange = (route) => {
this.setState({route: route});
}
render() {
if (this.state.route === 'Home') {
return (
<div className='App home'>
<div style={{display: 'flex', justifyContent: 'flex-end', backgroundColor: 'rgb(91,121,97, 0.5)'}}>
<div style={{marginRight: 'auto'}}><Logo onRouteChange={this.onRouteChange}/></div>
<Navigation onRouteChange={this.onRouteChange}/>
</div>
<SideBar/>
</div>
)
} else {
return(
<div className='App theAnimalKingdom'>
<div style={{display: 'flex', justifyContent: 'flex-end', backgroundColor: 'rgb(91,121,97, 0.5)'}}>
<div style={{marginRight: 'auto'}}><Logo onRouteChange={this.onRouteChange}/></div>
<Navigation onRouteChange={this.onRouteChange}/>
</div>
</div>
)
}
}
}
export default App;
The app.css is shown below.
div.app {
height: 100%;
width: 100%;
}
div.home {
background-image: url('./Images/cover.jpg') no-repeat center bottom fixed;
background-size: 100% 100%;
}
div.theAnimalKingdom {
background-image: url('./Images/other.jpg') no-repeat center bottom fixed;
background-size: 100% 100%;
}
If the this.status should change to theAnimalKingdom then the background should change to other.jpg