Udemy - Complete React Developer
BrowserRouter, Switch, Route, exact, Link
withRouter
routing된 페이지는 아래 세가지를 props로 받는다
ex)
<Route exact={false} path="/detail/:itemId' />
<Link to='localhost:3000/detail/13/1234?month=2020-12#hashhash'>move</Link>
false
{ itemId: "13" }
/detail/:itemId
/detail/13
/detail/13/1234
?month=2020-12
#hashhash
// 보통은 주소string으로 이동하지만
<Link to="/somewhere"/>
// location을 이용할수도 있음
const location = {
pathname: '/somewhere',
state: { fromDashboard: true }
}
<Link to={location}/>
<Redirect to={location}/>
history.push(location)
history.replace(location)
history.location와 location은 내용은 같지만
history는 mutable하기때문에 lifeCycle에서 사용시 조심해야함
componentWillReceiveProps(nextProps) {
if (nextProps.location !== this.props.location) {
// navigated!
}
if (nextProps.history.location !== this.props.history.location) {
// alawys false
}
}
HOC : Higher Order Component
Props Drilling/Tunneling : props를 깊숙히 넣어주기 위해 계속 전달하는 패턴