Skip to content
Permalink
Browse files

Add routes and update NavBar

  • Loading branch information
ivarprudnikov committed Jan 2, 2020
1 parent e17d175 commit f2fe93e7f1784372c9ae26f3401a0c9a80afe0b0
Showing with 21 additions and 12 deletions.
  1. +13 −12 src/App.js
  2. +8 −0 src/components/NavBar.js
@@ -1,20 +1,21 @@
import React from 'react';
import React from "react";
import NavBar from "./components/NavBar";
import { useAuth0 } from "./react-auth0-spa";
import { Router, Route, Switch } from "react-router-dom";
import Profile from "./components/Profile";
import history from "./utils/history";

function App() {

const { loading } = useAuth0();

if (loading) {
return <div>Loading...</div>;
}

return (
<div className="App">
<header>
<NavBar />
</header>
<Router history={history}>
<header>
<NavBar />
</header>
<Switch>
<Route path="/" exact />
<Route path="/profile" component={Profile} />
</Switch>
</Router>
</div>
);
}
@@ -1,5 +1,6 @@
import React from "react";
import { useAuth0 } from "../react-auth0-spa";
import { Link } from "react-router-dom";

const NavBar = () => {
const { isAuthenticated, loginWithRedirect, logout } = useAuth0();
@@ -11,6 +12,13 @@ const NavBar = () => {
)}

{isAuthenticated && <button onClick={() => logout()}>Log out</button>}

{isAuthenticated && (
<span>
<Link to="/">Home</Link>&nbsp;
<Link to="/profile">Profile</Link>
</span>
)}
</div>
);
};

0 comments on commit f2fe93e

Please sign in to comment.
You can’t perform that action at this time.