NavBar.module.css
.nav {
display: flex;
justify-content: space-between;
background-color: tomato;
}
.active {
color: red
}
NavBar.js
**import <u>styles</u> from "./NavBar.module.css"**
export default function NavBar() {
return (
<nav **className={<u>styles</u>.nav}**>
<Link href="/">
<a style={{ color: router.pathname === '/' ? "red" : "black" }}>Home</a>
</Link>
<Link href="/">
<a className=**{routerpathnme === '/' ? styles.active : ''}**>Home</a>
</Link>
</nav>
)
}
다른 클래스명도 같이 써야 할 때?
.link {
text-decoration: none;
}
.active {
color: tomato;
}
<Link href="/about">
<a className={
`${styles.link} ${router.pathname === '/about' ? styles.active : ""} `
}>About</a>
</Link>
<Link href="/about">
<a className={
[styles.link, router.pathname === '/about' ? styles.active : ""].join(" ")
}>About</a>
</Link>
a.js