[React] withRouterHOC

Wontae·2020년 9월 6일
0
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';

class Login extends Component {

  goToMain = () => {
    this.props.history.push('/signup' : null);
  }

  render() {
    return (
      <div>
        <button
          class="loginBtn"
          onClick={this.goToMain}
        >
          로그인
        </button>
      </div>
    )
  }
}

export default withRouter(Login);

<Link /> 를 사용하지 않고 요소에 onClick 이벤트를 통해 페이지를 이동하는 방법

profile
안녕하세요! 프론트엔드 개발자 정원태입니다.

1개의 댓글

comment-user-thumbnail
2020년 9월 29일

잘 보고 갑니다~

답글 달기