Skip to content

Commit

Permalink
#31 [ Router ] React Router
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Sep 21, 2023
1 parent 1bb604b commit a340f0e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/routers/2.Dynamic Routes/About.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const About = () => {
return (
<>
<h2>About</h2>
</>
);
};

export default About;
13 changes: 13 additions & 0 deletions src/routers/2.Dynamic Routes/Detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { useParams } from 'react-router-dom';

const Detail = () => {
const { id } = useParams();
return (
<>
<h2>Detail --- {id}</h2>
</>
);
};

export default Detail;
11 changes: 11 additions & 0 deletions src/routers/2.Dynamic Routes/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const Home = () => {
return (
<>
<h2>Home</h2>
</>
);
};

export default Home;
30 changes: 29 additions & 1 deletion src/routers/Main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
//* REACT
import React from 'react';

//* LIBRARY
import { Link, Route, Routes } from 'react-router-dom';

import Home from './2.Dynamic Routes/Home';
import About from './2.Dynamic Routes/About';
import Detail from './2.Dynamic Routes/Detail';

const Main = () => {
return (
<>
<h1>Main</h1>
{/* ------- */}
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
</ul>
</nav>
{/* ------- */}
<React.Fragment>
<div className="App">
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/detail/:id" element={<Detail />} />
</Routes>
</div>
</React.Fragment>
</>
);
};
Expand Down

0 comments on commit a340f0e

Please sign in to comment.