React Hooks路由跳转

import React from 'react';
import { useHistory } from 'react-router-dom';
import { PoweroffOutlined } from '@ant-design/icons';
import './index.css';

export default function HeaderUser() {

    let history = useHistory();

    function handleLogin() {
        history.push('/');
    }

    return(
        <div className='header-user'>
            user 
            <span className='header-user-click' onClick={handleLogin}>
                <PoweroffOutlined />
            </span>
        </div>
    )
}

React Hooks路由跳转_第1张图片
点击登陆按钮,即可根据路由跳转登陆页面。

你可能感兴趣的:(React)