npx create-react-app
jsconfig.json
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
npm i react-router-dom
4-1. Router Composition :
<Route path="/" component={Home}/>
<Route path="/go" component={go}/>
위 같은 코드에서 go url로 이동하면 화면에
Home과 go 둘 다 랜더링 된다. 이를 Composition 이라고 하고
이를 막기 위해선
<Route path="/" exact component={Home}/>
<Route path="/go" exact component={go}/>
exact를 prop으로 넣어줘야 한다
다른 방법으로는
<Switch>
<Route path="/" component={Home}/>
<Route path="/go" component={go}/>
</Switch>
Switch는 위에서 내려오면 서 url이 일치하는 한개의 라우터를 랜더한다.
5-1 withRouter
npm i styled-components
import {Link} from "react-router-dom";
const SLink = styled(Link)`
...css
`;
<SLink to="/">Home</SLink>
위는 Link와 styled component 결합
const api = axios.create({
baseUrl : "",
params : {
"api_key" : "",
...
}
})
```