Skip to content

Commit ebad00b

Browse files
committed
show active link in navbar
1 parent 223e3af commit ebad00b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/components/Navbar.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import { Terminal } from 'react-feather';
3-
import { Link } from 'react-router-dom';
3+
import { Link, withRouter } from 'react-router-dom';
44
import ReactTooltip from 'react-tooltip';
55

66
const Navbar = () => {
7+
const active = window.location.pathname;
78
document.addEventListener('DOMContentLoaded', () => {
89
const $navbarBurgers = Array.prototype.slice.call(
910
document.querySelectorAll('.navbar-burger'),
@@ -61,20 +62,28 @@ const Navbar = () => {
6162

6263
<div id='navbarBasicExample' className='navbar-menu'>
6364
<div className='navbar-end'>
64-
<Link className='navbar-item' to='/' data-tip='Go to Home page'>
65+
<Link
66+
className={`navbar-item ${active === '/' ? 'is-active' : ''}`}
67+
to='/'
68+
data-tip='Go to Home page'
69+
>
6570
Home
6671
</Link>
6772

6873
<Link
69-
className='navbar-item'
74+
className={`navbar-item ${
75+
active.includes('/resources') ? 'is-active' : ''
76+
}`}
7077
to='/resources'
7178
data-tip='Go to Resources Page'
7279
>
7380
Resources
7481
</Link>
7582

7683
<Link
77-
className='navbar-item'
84+
className={`navbar-item ${
85+
active === '/bookmarked' ? 'is-active' : ''
86+
}`}
7887
to='/bookmarked'
7988
data-tip='Go to Bookmarked Page'
8089
>
@@ -96,4 +105,4 @@ const Navbar = () => {
96105
);
97106
};
98107

99-
export default Navbar;
108+
export default withRouter(Navbar);

0 commit comments

Comments
 (0)