小编arp*_*rpl的帖子

在typescript中创建自己的react路由类

我找到了这个(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课程也会有所帮助,谢谢.

typescript reactjs react-router react-router-v4

12
推荐指数
4
解决办法
6372
查看次数