我有一个用户,我想在模型中创建一个辅助函数,以查看用户是否为Admin,例如:
export class User {
email;
password;
profile;
constructor(email, password, profile) {
this.email = email;
this.password = password;
this.profile = profile;
}
isAdmin() {
return this.profile && this.profile.name === "ADMIN"
}
}
并致电:
<BrowserRouter>
<div>
<Switch>
{(user.isAdmin()) && <Redirect to={`/route`}/>}
</Switch>
</div>
</BrowserRouter>
但是我得到:
TypeError: user.isAdmin is not a function
我应该怎么做?我使用Redux