-
#18 React Router DomNode.js/[챕터1] 2021. 7. 15. 22:00728x90
// react-router-dom을 설치한다! npm install react-router-dom --save
// app.js에서 import React from "react"; import LandingPage from "./components/views/LandingPage/LandingPage"; import LoginPage from "./components/views/LoginPage/LoginPage"; import RegisterPage from "./components/views/RegisterPage/RegisterPage"; import {BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"; function App() { return ( <Router> <div> <Switch> <Route exact path="/"> <LandingPage /> </Route> <Route exact path="/login"> <LoginPage /> </Route> <Route exact path="/RegisterPage"> <RegisterPage /> </Route> </Switch> </div> </Router> ); } export default App;
이렇게 하면 localhost:3000으로 접속하면 LandingPage가 나오고 localhost:3000/login 으로 접속하면 LoginPage
localhost:3000/register로 접속하면 RegisterPage가 나오는걸 볼 수 있다!.
728x90'Node.js > [챕터1]' 카테고리의 다른 글
#20 CORS 이슈, Proxy 설정 (0) 2021.07.25 #19 데이터 Flow & Axios (0) 2021.07.15 [17]CRA to Our Boilerplate (0) 2021.07.10 #16 Create-React-App (0) 2021.07.10 #14 로그아웃 기능 (0) 2021.06.08