Javascript 将用户重定向到不同的页面取决于React中的用户类型
我对Javascript 将用户重定向到不同的页面取决于React中的用户类型,javascript,reactjs,redux,react-redux,react-router,Javascript,Reactjs,Redux,React Redux,React Router,我对react和redux是新手。在这里,我试图根据用户类型将用户重定向到不同的页面。我所拥有的是 我的main.js文件 class Main extends Component { componentDidMount() { this.props.isUserAuthenticated(); } render() { return ( <Router history={history}> <div>
react和redux
是新手。在这里,我试图根据用户类型将用户重定向到不同的页面。我所拥有的是
我的main.js文件
class Main extends Component {
componentDidMount() {
this.props.isUserAuthenticated();
}
render() {
return (
<Router history={history}>
<div>
{this.props.isFetching && <Loading />}
<Switch>
<PrivateRoute exact path="/" component={LandingPage} />
<PrivateRoute exact path="/create-job" component={NewJob} />
<PrivateRoute exact path="/create-job/new" component={SelectCriteriaNewJob} />
<PrivateRoute exact path="/view-job" component={ViewJob} />
<PrivateRoute exact path="/resume-list/:jdId" component={ResumeList} />
<PrivateRoute exact path="/DashBoard" component={DashBoard} />
<Route exact path="/login" component={Login} />
<Route exact path="/*" component={NotFound} something="foo" />
</Switch>
</div>
</Router>
)
}
}
现在,在这个操作中,我将用户重定向到/
页面,其中,组件如下所示:
render() {
if (this.state.isloading) {
return null;
}
else if (this.props.jobs) {
return <JobList />;
} else if (this.props.error) {
return <ErrorComponent />
}
else {
return <Redirect to="/create-job" />
}
}
}
render(){
if(此.state.isloading){
返回null;
}
else if(this.props.jobs){
返回;
}else if(this.props.error){
返回
}
否则{
返回
}
}
}
现在,当用户登录时,我得到一个令牌,它是JWT
令牌,该令牌包含一些信息。因此,如果用户类型是admin,我想将用户重定向到/Dashboard
页面。因此,可能会有不同的角色,
我有什么办法可以做到这一点吗
谢谢。您能告诉我们您到目前为止都做了哪些尝试吗。您也可以通过提供相同的代码沙盒来提供更多信息。您可以向我们展示您迄今为止所做的尝试吗。您还可以通过提供相同的代码沙盒来提供更多信息。
render() {
if (this.state.isloading) {
return null;
}
else if (this.props.jobs) {
return <JobList />;
} else if (this.props.error) {
return <ErrorComponent />
}
else {
return <Redirect to="/create-job" />
}
}
}