useLocation을 이용해서 현재 페이지의 URL을 가져올 수 있다.
import { useLocation } from 'react-router-dom';
const location = useLocation();
const location = useLocation();
useEffect(() => {
console.log(location);
}, [location])
# styled-componet 부분
const StyledNavbar = styled(Navbar)`
background-color : ${props => props.pathname === '/' || props.pathname === '/login' || props.pathname === '/Signin' ? 'rgb(37 37 37 / 5%)' : 'white'};
`
# 선언
function Navs() {
const pathname = useLocation().pathname
}
return (
<StyledNavbar pathname={pathname} collapseOnSelect expand="lg" variant={pathname==='/' || pathname==='/login' || pathname==='/Signin' ? 'dark':'light'} >