<StyledApp>
<BrowserRouter>
<Switch>
<Route path="/" component={Main} />
</Switch>
</BrowserRouter>
</StyledApp>
<Box width="100%" height="100%">
<Header />
<SideBar />
<BodyBox flex={1}>
<Switch>
<Route path="/" exact component={LiveCollection} />
<Route path="/channel" component={Channel} />
<Route path="/socket" component={SocketTest} />
</Switch>
</BodyBox>
</Box>
params
를 사용하는 것query
를 사용하는 것라우트로 설정한 컴포넌트는 총 3가지의 props를 전달받게 된다.
push
, replace
를 하며 다른 경로로 이동하거나 앞 뒤 페이지로 전환 가능"/about/:name" URL이라고 가정해보자
import React from 'react';
const About = ({match}) => {
return (
<div>
<h2>About {match.params.name}</h2>
</div>
);
};
export default About;
⇒ match.params.name
으로 param name의 값을 확인 가능