我正在尝试在react-router v4中解决重定向问题。如果用户登录,我想重定向到Index组件,当用户注销时,我想重新加载显示CodeClient组件。
我从不使用react-router-dom
,怎么办呢?
有人可以解释我并告诉我代码怎么做?
这是我的代码:
import React, { Component } from 'react';
import './App.css';
import CodeClient from './components/Login/CodeClient';
import IndexComponent from './components/Index/IndexComponent';
class App extends Component {
constructor(props) {
super(props);
this.state = { user: undefined, logged: false };
}
doParentCode = (user) => {
// when user is different of undefined
this.setState({ logged:true, user: user});
}
render() {
return (
<div className="Loggin">
{
(!this.state.logged) ? <CodeClient parentCode={this.doParentCode} /> : <IndexComponent user={this.state.user}/>
}
</div>
);
}
}
export default App;