From ba5515f42e0cc18a74bff4daf5609845be80846f Mon Sep 17 00:00:00 2001 From: tester Date: Mon, 7 Oct 2024 14:48:35 +0530 Subject: [PATCH] navbar added --- frontend/src/components/MainNavbar.tsx | 48 +++++++++++++ frontend/src/components/loading.tsx | 9 +++ frontend/src/components/routes/mainroute.jsx | 71 +++++++++++--------- 3 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 frontend/src/components/MainNavbar.tsx create mode 100644 frontend/src/components/loading.tsx diff --git a/frontend/src/components/MainNavbar.tsx b/frontend/src/components/MainNavbar.tsx new file mode 100644 index 0000000..895a13f --- /dev/null +++ b/frontend/src/components/MainNavbar.tsx @@ -0,0 +1,48 @@ +import React, { useEffect, useState } from 'react'; +import { Outlet, useNavigate } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; +import { Link } from 'react-router-dom'; +const Navbar = () => { + const navigate = useNavigate(); + const location = useLocation(); + useEffect(() => { + console.log("here"); + if (location.pathname === '/') navigate("/homepage"); + }, [location]); + return ( +
+ + +
+ ); +}; + +export default Navbar; diff --git a/frontend/src/components/loading.tsx b/frontend/src/components/loading.tsx new file mode 100644 index 0000000..f337bdf --- /dev/null +++ b/frontend/src/components/loading.tsx @@ -0,0 +1,9 @@ +import React from "react" +export default function Loader(){ + return( +
+
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/routes/mainroute.jsx b/frontend/src/components/routes/mainroute.jsx index 4d69778..3299f29 100644 --- a/frontend/src/components/routes/mainroute.jsx +++ b/frontend/src/components/routes/mainroute.jsx @@ -10,6 +10,8 @@ import HomePage from "../../pages/HomePage"; import Register from "../Register"; import SinglePost from "../../components/SinglePost"; import LoginPage from "../Login"; +import Navbar from "../MainNavbar"; +import Loader from "../loading"; const Test = () => { const [userId, setUserId] = useState(""); const [roomId, setRoomId] = useState(""); @@ -47,45 +49,52 @@ const Test = () => { const Mainrouter = createBrowserRouter([ { path: "/", - element: , - }, - { - path: "/posts", - element: , - }, - { - path: "/posts/:id", - element: , - }, - { - path: "/login", - element: , - }, - { - path: "/signup", - element: , - }, - { - path: "/room", - element: , - children: [ + element: , + children:[ { - path: "/room", - element: , - index: true, + path:"homepage", + element: + }, + { + path: "posts", + element: , }, { - path: "/room/createroom", - element: , + path: "posts/:id", + element: , }, { - path: "/room/joinroom", - element: , + path: "login", + element: , }, { - path: "/room/chatting", - element: , + path: "/signup", + element: , }, + { + path: "/room", + element: , + children: [ + { + path: "/room", + element: , + index: true, + }, + { + path: "/room/createroom", + element: , + }, + { + path: "/room/joinroom", + element: , + }, + { + path: "/room/chatting", + element: , + }, + ], + }, + ], }, ]);