summaryrefslogtreecommitdiff
path: root/src/routes/index.js
blob: af1b70b59cb9936e22d644937ccad5291ef06c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React from 'react';
import {BrowserRouter, Redirect, Route, Switch} from "react-router-dom";
import {userIsLoggedIn} from "../auth/index";
import Home from "../pages/Home";
import NotFound from "../pages/NotFound";
import Profile from "../pages/Profile";
import Simulations from "../pages/Simulations";

const ProtectedComponent = (component) => () => userIsLoggedIn() ? component : <Redirect to="/"/>;

const Routes = () => (
    <BrowserRouter>
        <Switch>
            <Route exact path="/" component={Home}/>
            <Route exact path="/simulations" render={ProtectedComponent(<Simulations/>)}/>
            <Route exact path="/profile" render={ProtectedComponent(<Profile/>)}/>
            <Route path="/*" component={NotFound}/>
        </Switch>
    </BrowserRouter>
);

export default Routes;