LocChat/client/components/router.jsx

22 lines
678 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-20 21:34:10 -05:00
import { SettingsContext } from '../utils/settings_context';
import { SignIn } from './sign_in/_sign_in';
import { SignUp } from './sign_up/_sign_up';
2021-11-20 20:18:58 -05:00
export const Router = () => {
2021-11-20 21:34:10 -05:00
const [settings] = useContext(SettingsContext);
2021-11-22 16:21:53 -05:00
const { jwt } = settings;
2021-11-20 20:18:58 -05:00
return (
<Routes>
2021-11-20 21:34:10 -05:00
<Route
path="/"
2021-11-22 16:21:53 -05:00
element={jwt ? <Home /> : <Navigate replace to="signin" />} // no jwt means not logged in
2021-11-20 21:34:10 -05:00
/>
<Route path="signin" element={<SignIn />} />
<Route path="signup" element={<SignUp />} />
2021-11-20 20:18:58 -05:00
</Routes>
);
};