react函数组件路由跳转


react函数组件路由跳转

import React, { useState, useEffect } from 'react'
import { useHistory } from "react-router-dom";

import cx from 'classnames'
import './index.css'

interface resLogin {
  code?: number,
  data?: object
}

const Login: React.FC<{}> = (props) => {
  
  let history = useHistory();

  const onFinish = async (values: any) => {
    const { username, password } = values
    let result = await userLogin({ params: { username, password } }) as resLogin
    
    if(result.code === 200){
      history.push("/layout");
    }
  };

  return (
    <div className={cx('container')}>
      <div className={cx('loginCard')}>
          { ...  }
      </div>
    </div>
  )
}

export default Login

文章作者: KarlFranz
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 reprint policy. If reproduced, please indicate source KarlFranz !
评论
  目录