我找到了这个(reacttraining.com)网站,它用一些例子解释了react-router.但是我无法用打字稿类做到这一点.我想要做的是扩展Route类来构建我自己的类.现在我想在typescript中实现它以进行身份验证,如以下示例所示.
const PrivateRoute = ({ component, ...rest }) => (
<Route {...rest} render={props => (
fakeAuth.isAuthenticated ? (
React.createElement(component, props)
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
)
Run Code Online (Sandbox Code Playgroud)
我搜索了很多,但找不到一个解释要实现的函数的站点以及调用嵌套路由的类型属性.ES6课程也会有所帮助,谢谢.