LocChat/client/components/router.jsx

26 lines
843 B
React
Raw Normal View History

2021-11-20 21:34:10 -05:00
import { useContext } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
2021-11-20 20:18:58 -05:00
import { Home } from './home/_home';
2021-11-23 16:04:12 -05:00
import { AuthContext } from '../utils/auth_context';
2021-11-20 21:34:10 -05:00
import { SignIn } from './sign_in/_sign_in';
import { SignUp } from './sign_up/_sign_up';
2021-12-01 22:18:26 -05:00
import { Admin } from './admin/_admin';
2022-03-31 00:15:20 -04:00
import { ChatRoom } from './chatroom/_chat_room';
2021-11-20 20:18:58 -05:00
export const Router = () => {
2021-11-23 16:04:12 -05:00
const [authToken] = useContext(AuthContext);
2021-11-20 20:18:58 -05:00
return (
<Routes>
2021-11-20 21:34:10 -05:00
<Route
path="/"
2021-11-30 17:40:07 -05:00
element={authToken ? <Home /> : <Navigate replace to="signin" />} // no token means not logged in
2021-11-20 21:34:10 -05:00
/>
2021-12-01 22:18:26 -05:00
<Route path="admin" element={<Admin />} />
2021-11-20 21:34:10 -05:00
<Route path="signin" element={<SignIn />} />
<Route path="signup" element={<SignUp />} />
2022-03-31 00:15:20 -04:00
<Route path="rooms/:id" element={<ChatRoom />} />
2021-11-20 20:18:58 -05:00
</Routes>
);
};