You can get access to the history object’s properties and the closest <Route
>'s match via the withRouter higher-order component. withRouter will pass updated match, location, and history props to the wrapped component whenever it renders.
-라우트가 아닌 컴포넌트에서,라우터에서 사용하는 객체 - location, match, history 를 사용하려면, withRouter 라는 HoC 를 사용.
-withrouter는 다른 컴포넌트를 감싼 컴포넌트이며, router에 대한 정보를 줌.
import { withRouter } from "react-router-dom";
export default withRouter(({ location: { pathname } }) => (
<Header>
<List>
<Item current={pathname === "/"}>
<SLink to="/">Movies</SLink>
</Item>
<Item current={pathname === "/tv"}>
<SLink to="/tv">TV</SLink>
</Item>
<Item current={pathname === "/search"}>
<SLink to="/search">Search</SLink>
</Item>
</List>
</Header>
));