reactjs - If <notFound/> component get executed add class to <footer/>component . React-Redux -


if < notfound /> rout executed (i.e : if not found page rendered want add class footer component.

below index.jsx render function

    render() {     return (         <div>             <navbar />             <div classname="pagedata">                 {this.props.children}                 // <notfound/> component rendered here             </div>             <footer/>             <loginpopup />         </div>     ) } 

below routes.jsx

 import react 'react' import { route, indexroute } 'react-router' import app 'layout/app' import home 'pages/home' import mywagers 'containers/mywagerscontainer' import wagers 'containers/wagerscontainer' import notfound 'pages/notfound'  const routes = ( <route path='/' component={app}>     <indexroute component={home} />     <route path="/wagers(/:trackcode)(/:racenum)" component={wagers} >         <route path="*" component={() => (<notfound status = "404" />)}/>     </route>     <route path="/mywagers" component={mywagers} />     <route path="*" name = "notfound" component={() => (<notfound status =  "404" />)}/> </route> )  export default routes 

so can set globally or can route name can add class in footer component per < notfound / > component rendered

use callback pass this.props.children , in <notfound />

componentwillmount() {   this.props.setfooterclass('myclass'); }  componentwillunmount() {   this.props.setfooterclass(''); } 

in index.js:

 <notfound setfooterclass={myclass => this.setstate({ footerclass: myclass })} /> 

and

 <footer classname={this.state.footerclass} /> 

pass props children


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -