If you want to redirect a user to a certain URL using React:
jsximport React from 'react'; const RedirectButton = () => { return( <button onClick = {() => window.location.href = 'https://erikmartinjordan.com'}>Click me</button> ); } export default RedirectButton;
Or here is a more elegant solution:
jsxconst RedirectButton = ({url}) => { const redirect = () => { window.location.href = url; } return( <button onClick = {redirect}>Click me</button> ); } export default RedirectButton;
Now you can use the button like:
jsx<RedirectButton url = 'https://erikmartinjordan.com'/>
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.