0

This is my app.jsx and i want to access isAdmin state of Login Component into app.js...isAdmin identifies whether user is admin or not and based upon the value..i want to manipulate the routes....How i can achieve this ??

Please help i am new to react...

 import Login from './components/Forum/login';
 console.log("login",Login.this.state.isAdmin);

ReactDOM.render(
    <Router history={browserHistory}>
        <Route path="/" component={Base}>
         <IndexRoute component={isAdmin == true ? DashboardV1 : ChartFlot } />
            <Route path="dashboard" component={DashboardV1}/>
            <Route path="dashboardv2" component={DashboardV2}/>
            <Route path="dashboardv3" component={DashboardV3}/>
            <Route path="form-cropper" component={FormCropper}/>
    </Router>,
    document.getElementById('app')
);

1 Answers1

0

You can use React's refs to components.

in app.jsx

<Login ref="myLogin" />

... then call that component using ref.

console.log(this.refs.myLogin.isAdmin);

check out Facebook's documentation about React's Refs to Components here.

Juni Brosas
  • 1,425
  • 2
  • 14
  • 24