npm install react-router-dom --save
입력한다.+Router 활용해보기.
src 폴더의 index.js
파일에 Routes.js
파일을 생성한 후 Routes
컴포넌트를 만들어 연결시킨다.
index.js
import React from "react";
import ReactDOM from "react-dom";
import "./Styles/index.css";
import Routes from "./Routes"; //-> Routes 컴포넌트 연결
ReactDOM.render(<Routes />, document.getElementById("root"));
import React from "react";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Main from "./Pages/Main/";
import Login from "./Pages/Login/";
export default class Routes extends React.Component {
render() {
return (
<Router>
<Switch>
<Route exact path="/" component={Main} />
//=> Main컴포넌트와 연결
<Route exact path="/login" component={Login} />
//=> Login컴포넌트와 연결
</Switch>
</Router>
);
}
}