MenuBar.js
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, { useState } from "react";
import { Menu } from "semantic-ui-react";
import { Link } from "react-router-dom";
function MenuBar() {
const pathname = window.location.pathname;
const path = pathname === "/" ? "home" : pathname.substr(1);
const [activeItem, setActiveItem] = useState(path);
const handleItemClick = (e, { name }) => setActiveItem(name);
return (
<div>
<Menu size="massive" color="teal" pointing secondary>
<Menu.Item
name="home"
active={activeItem === "home"}
onClick={handleItemClick}
as={Link}
to="/"
/>
<Menu.Menu position="right">
<Menu.Item
name="login"
active={activeItem === "login"}
onClick={handleItemClick}
as={Link}
to="/login"
/>
<Menu.Item
name="register"
active={activeItem === "register"}
onClick={handleItemClick}
as={Link}
to="/register"
/>
</Menu.Menu>
</Menu>
</div>
);
}
export default MenuBar;