【发布时间】:2021-12-12 14:16:55
【问题描述】:
我有以下代码,我在其中渲染组件或根据身份验证状态重定向用户。我无法理解在我声明的界面中应该将组件道具类型设置为什么:
import { useState } from 'react';
import { Redirect, Route } from 'react-router-dom';
import { useAuthState } from '../../../context/authenticationContext';
interface AppProps {
path: string,
isPrivate: boolean,
}
const AppRoutes = ({ component: Component, path, isPrivate, ...rest }: AppProps) => {
const authDetails = useAuthState();
...
return (
<Route
path={path}
render={props => (isPrivate && !authDetails.user) ? (
<Redirect
to={{ pathname: "/" }}
/>
) : (
<Component {...props} />
)
}
{...rest}
/>
)
}
export default AppRoutes
如您所见,我的界面缺少组件类型。不知道要设置什么。
【问题讨论】:
标签: reactjs typescript react-typescript