React 화면 이동 및 데이터 전달하기
Post

React 화면 이동 및 데이터 전달하기

React의 @reach/router 모듈을 활용하여 화면 이동 및 데이터 전달을 해본다.

1
2
3
import { Link } from '@reach/router';

 <Link to="/test" state= { { info: 'hello' } }>MOVE</Link>
1
2
3
4
5
import { navigate } from '@reach/router';

<Button onClick={()=> {
  navigate('/test', {state: { info: 'hello' }})
}}>MOVE</Button>

데이터 받기

1
2
3
const ViewDocument = ({location}) => {
  const data = location.state.info;
}