LocChat/client/components/router.jsx
2022-03-30 22:15:20 -06:00

26 lines
843 B
JavaScript

import { useContext } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { Home } from './home/_home';
import { AuthContext } from '../utils/auth_context';
import { SignIn } from './sign_in/_sign_in';
import { SignUp } from './sign_up/_sign_up';
import { Admin } from './admin/_admin';
import { ChatRoom } from './chatroom/_chat_room';
export const Router = () => {
const [authToken] = useContext(AuthContext);
return (
<Routes>
<Route
path="/"
element={authToken ? <Home /> : <Navigate replace to="signin" />} // no token means not logged in
/>
<Route path="admin" element={<Admin />} />
<Route path="signin" element={<SignIn />} />
<Route path="signup" element={<SignUp />} />
<Route path="rooms/:id" element={<ChatRoom />} />
</Routes>
);
};