How to make the button redirect to another page in Reag

I have a component that has onClick: onClick: PropTypes.func in its onClick: PropTypes.func

In another component, I use this component several times to fill the page. Each of these components has a title that, when clicked, should redirect to another page.

The problem is that it does not work when I click on it. He does not do anything. This is a render of the main component:

 render() { return ( <Class title={account.AccountName} onClick={() => "mySite/accountview?id=" + account.AccountName} > </Class> ... ); } 

What should I add to onClick to make it work?

+5
source share
1 answer

You need to use a React Router .

With Link :

 <Link to={`/mySite/accountview?id=${account.AccountName}`}>something</Link> 

With onClick :

 <button onClick={() => hashHistory.push(`/mySite/accountview?id=${account.AccountName}`)}></button> 

You can use hashHistory or browserHistory : D

+2
source

Source: https://habr.com/ru/post/1269065/


All Articles