diff --git a/package.json b/package.json
index f0713d8..7088f15 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,7 @@
"npm": "^7.21.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
+ "react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"uniqid": "^5.3.0",
"web-vitals": "^1.1.2"
diff --git a/src/Routes.js b/src/Routes.js
new file mode 100644
index 0000000..9bafddb
--- /dev/null
+++ b/src/Routes.js
@@ -0,0 +1,18 @@
+import { BrowserRouter, Switch, Route } from "react-router-dom";
+import App from "./App";
+import PostDetail from "./components/PostDetail";
+
+const Routes = () => {
+ const posts = "/posts";
+ return (
+
+
+
+
+
+
+
+ );
+};
+
+export default Routes;
diff --git a/src/components/PostDetail.js b/src/components/PostDetail.js
new file mode 100644
index 0000000..885e777
--- /dev/null
+++ b/src/components/PostDetail.js
@@ -0,0 +1,41 @@
+import { useState, useEffect } from "react";
+import { useParams } from "react-router-dom";
+
+import { getPost } from "../data/source/blogApi";
+
+const PostDetail = () => {
+ const [post, setPost] = useState({
+ title: "",
+ timestamp: "",
+ text: "",
+ user: {
+ username: "",
+ password: "",
+ },
+ });
+
+ const { id } = useParams();
+
+ useEffect(() => {
+ const pullPost = async () => {
+ setPost(await getPost(id));
+ };
+ pullPost();
+ }, [id]);
+
+ let { title, timestamp, text, user } = post;
+ return (
+
+
{title}
+
- {user.username}
+
{timestamp}
+
+
{text}
+
+
TODO: add comments
+
TODO: display comments
+
+ );
+};
+
+export default PostDetail;
diff --git a/src/data/source/blogApi.js b/src/data/source/blogApi.js
index 1c0c399..ade9302 100644
--- a/src/data/source/blogApi.js
+++ b/src/data/source/blogApi.js
@@ -1,9 +1,15 @@
const API_URL = process.env.REACT_APP_API_URL;
+const getPost = async (id) => {
+ const response = await fetch(`${API_URL}/posts/${id}`, { mode: "cors" });
+ const post = await response.json();
+ return post;
+};
+
const getPosts = async () => {
const response = await fetch(`${API_URL}/posts`, { mode: "cors" });
const posts = await response.json();
return posts;
};
-export { getPosts };
+export { getPost, getPosts };
diff --git a/src/index.js b/src/index.js
index a9d5395..cd3d08f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,11 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
-import App from "./App";
+import Routes from "./Routes";
document.title = "Blog Reader";
ReactDOM.render(
-
+
,
document.getElementById("root")
);