【发布时间】:2020-08-14 22:29:22
【问题描述】:
我正在创建一个反应应用程序,当我的应用程序启动时,我想知道用户是否登录以将他发送到主页。 当我的应用启动“/”路由时加载此页面
import React from 'react';
import { Redirect } from 'react-router';
import { LocalStorageService } from "../services/localData-service";
const HomeOrLogin : React.FC = () => {
/*If User is logged then, redirect to home, if not redirect to slides tutorial*/
const storageService = new LocalStorageService();
// Check if exits jwt in the phone
storageService.getItem("jwt")
.then((token )=>{
/* If exists the jwt in the phone the user is logged */
if(token){
return <Redirect to="/Home" />
}else{
return <Redirect to="/slides" />
}
})
.catch((err)=>{
console.log(err);
})
};
export default HomeOrLogin;
但它显示组件中有错误
Type '() => void' is not assignable to type 'FC<{}>'.
Type 'void' is not assignable to type 'ReactElement<any, any> | null'.
【问题讨论】:
标签: reactjs ionic-framework react-hooks react-functional-component