Skip to content

Commit fa5f2bf

Browse files
committed
added Link component and made the navbar brand a link
1 parent 9d27d29 commit fa5f2bf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/components/Link.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
3+
const Link = ({children,to}) => {
4+
5+
const navigate = (event) =>{
6+
event.preventDefault()
7+
window.history.pushState(null,null,to)
8+
window.dispatchEvent(new PopStateEvent('popstate'))
9+
}
10+
11+
return (
12+
<a onClick={navigate} href={to}>
13+
{children}
14+
</a>
15+
)
16+
}
17+
18+
export default Link

src/components/common/Navbar/Navbar.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import './Navbar.css'
33
import BrandLogo from '../../../assets/logos/BrandLogo';
44
import DashboardForm from '../../Dashboard/DashboardForm/DashboardForm';
55
import { LoginContext } from '../../../contexts/LoginContext';
6+
import Link from '../../Link';
7+
68

79
const Navbar = () => {
810

@@ -12,7 +14,9 @@ const Navbar = () => {
1214
<nav className="navbar navbar-dark py-3">
1315
<div className="container">
1416
<span className="navbar-brand">
15-
<BrandLogo/>
17+
<Link to={isLoggedIn ? '/search-screen' : '/'}>
18+
<BrandLogo/>
19+
</Link>
1620
</span>
1721
{
1822
isLoggedIn &&

0 commit comments

Comments
 (0)