skip to Main Content

im doing a website with antd and i want to do spa website. So, when user clicks on any btn in menu, the content would change. But i cant put my link component in onClick func. Code is there:

<Menu  theme="dark" defaultSelectedKeys={['9']} mode="inline" items={items} onClick={(item) => {
          if (item.key === '1'){
            console.log(1);
            //LINK THERE
          } 

        }}/>

I tried to put menu in link tag. it works, but its not what i wanted to.

2

Answers


  1. Chosen as BEST ANSWER

    It solves with useNavigate hook. just put in it your path and it will work


  2. use vanila.js. This can detect all button elements that are clicked

    document.querySelectorAll("button").forEach(e => {
          e.addEventListener("click", myFunction);
        }
      )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search