Skip to content

Add Icon #20

Answered by j471n
therockstarind asked this question in Q&A
Feb 12, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

You can do two things -

FIRST

const navigationRoutes = [
  {
    route: "/",
    name:"Home",
    Icon: <HomeIcon />
  },
//........more routes
// something like that
]

Then import this in your navbar and use it.

navigationRoutes.map(nav => (
   <Link href={nav.route}>
      {nav.Icon}
     <p>{nav.name}</p>
   </Link>
))

SECOND

const navigationRoutes = [
  "home",
  "about",
  "blog",
]

now what you can do is create a function that will return the Icon based on the navigation route name such as following:

// import icons...........

export function getIcon(route) {
  switch(route) {
   case "home"
     return <HomeIcon />
   case "about":
     return <AboutIcon />
   case "about":
     r…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@therockstarind
Comment options

@j471n
Comment options

Answer selected by therockstarind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants