Accepted answer

While this will render in a web browser, beware that:
⚠️Nesting an html button in an html a (or vice-versa) is not valid html ⚠️. If you want to keep your html semantic to screen readers, use another approach.

Do wrapping in the reverse way and you get the original button with the Link attached. No CSS changes required.

 <Link to="/dashboard">
     <button type="button">
          Click Me!

Here button is HTML button. It is also applicable to the components imported from third party libraries like Semantic-UI-React.

 import { Button } from 'semantic-ui-react'
 <Link to="/dashboard">
     <Button style={myStyle}>
        <p>Click Me!</p>


As I searched through answers everyone was talking about the old versions of react-router-dom, so this might be useful answer for those who want to use the hooks in functional components. As in the new version few hooks are changed and even the withRouter is not applicable you need to make a custom HOC.

we can achieve it through functional components you can use your button and then describe onClick event to trigger to the next page through useNavigate hook.

React-Router-Dom version 6

this is only possible in functional components as i am using hooks, if you want to use on class components then you can make hoc.

import {Link, useNavigate} from 'react-router-dom';
function Home() {
you can pass your state like so:  navigate('/show',{state});
const toShowInfoPage=()=>{



 /*you can use button as well or anything 
of your choice, but remember 
you have to pass the onClick event.




To access useNavigate() with a class component you must either convert to a function component, or roll your own custom withRouter Higher Order Component to inject the "route props" like the withRouter HOC from react-router-dom v5.x did.

This is just a general idea. if you want to useNavigate Here's an example custom withRouter HOC:

const withRouter = WrappedComponent => props => {
  const params = useParams();
  // etc... other react-router-dom v6 hooks

  return (
      // etc...

And decorate the component with the new HOC.

export default withRouter(Post);

This will inject a props for the class component.


Many of the solutions have focused on complicating things.

Using withRouter is a really long solution for something as simple as a button that links to somewhere else in the App.

If you are going for S.P.A. (single page application), the easiest answer I have found is to use with the button's equivalent className.

This ensures you are maintaining shared state / context without reloading your entire app as is done with

import { NavLink } from 'react-router-dom'; // 14.6K (gzipped: 5.2 K)

// Where link.{something} is the imported data
<NavLink className={`bx--btn bx--btn--primary ${link.className}`} to={link.href} activeClassName={'active'}>

// Simplified version:
<NavLink className={'bx--btn bx--btn--primary'} to={'/myLocalPath'}>
    Button without using withRouter


I recommend that you utilize the component prop on the Link component. Using this, you can have effectively any component behave as an a component from the perspective of React Rotuer. For instance, you can create your own "Button" component and then utilize this.

const MyButton = () => {
    return <button>Do something with props, etc.</button>

<Link to="/somewhere" component={MyButton}>Potentially pass in text here</Link>


Using react-router-dom and a function

In react, you can use react-router-dom by applying the useHistory call...

- Firstly

import { useHistory } from 'react-router-dom';

- Secondly Inside your function...write a function to handle the button click

const handleButtonClick = () => {

- Lastly

<button onClick={handleButtonClick} className="CSS">
   Button Text


<Button component={Link} to="/dashboard" type="button">
    Click Me!


With styled components this can be easily achieved

First Design a styled button

import styled from "styled-components";
import {Link} from "react-router-dom";

const Button = styled.button`
  background: white;
  font-size: 1em;
  margin: 1em;
  padding: 0.25em 1em;
  border: 2px solid red;
  border-radius: 3px;
    <Button as={Link} to="/home"> Text Goes Here </Button>

check styled component's home for more


I use Router and < Button/>. No < Link/>

<Button onClick={()=> {this.props.history.replace('/mypage')}}>


For anyone looking for a solution using React 16.8+ (hooks) and React Router 5:

You can change the route using a button with the following code:

<button onClick={() => props.history.push("path")}>

React Router provides some props to your components, including the push() function on history which works pretty much like the < Link to='path' > element.

You don't need to wrap your components with the Higher Order Component "withRouter" to get access to those props.


Update for React Router version 6:

The various answers here are like a timeline of react-router's evolution 🙂

Using the latest hooks from react-router v6, this can now be done easily with the useNavigate hook.

import { useNavigate } from 'react-router-dom'      

function MyLinkButton() {
  const navigate = useNavigate()
  return (
      <button onClick={() => navigate("/home")}>
        Go Home


You can use useHistory hook since react-router v5.1.0.

The useHistory hook gives you access to the history instance that you may use to navigate.

import React from 'react'
import { useHistory } from 'react-router-dom'

export default function SomeComponent() {
  const { push } = useHistory()
    onClick={() => push('/some-link')}
    Some link

NOTE: be aware that this approach answers the question but is not accessible like @ziz194 says in their comment

this is not accessible though, as the button will not be a tag and thus it doesn't have link behaviours, like opening the link in a new page. It is also not optimal for screen readers.

CONCLUSION: The better way to handle this is to use an <a> tag and style it.


If you are using react-router-dom and material-ui you can use ...

import { Link } from 'react-router-dom'
import Button from '@material-ui/core/Button';

<Button component={Link} to="/open-collective">

You can read more here.


Why not just decorate link tag with the same css as a button.

 className="btn btn-pink"


LinkButton component - a solution for React Router v4

First, a note about many other answers to this question.

⚠️ Nesting <button> and <a> is not valid html. ⚠️

Any answer here which suggests nesting a html button in a React Router Link component (or vice-versa) will render in a web browser, but it is not semantic, accessible, or valid html:

<a stuff-here><button>label text</button></a>
<button><a stuff-here>label text</a></button>

Click to validate this markup with

This can lead to layout/styling issues as buttons are not typically placed inside links.

Using an html <button> tag with React Router <Link> component.

If you only want an html button tag…

<button>label text</button>

…then, here's the right way to get a button that works like React Router’s Link component…

Use React Router’s withRouter HOC to pass these props to your component:

  • history
  • location
  • match
  • staticContext

LinkButton component

Here’s a LinkButton component for you to copy/pasta:

// file: /components/LinkButton.jsx
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'

const LinkButton = (props) => {
  const {
    // ⬆ filtering out props that `button` doesn’t know what to do with.
  } = props
  return (
      {} // `children` is just another prop!
      onClick={(event) => {
        onClick && onClick(event)

LinkButton.propTypes = {
  to: PropTypes.string.isRequired,
  children: PropTypes.node.isRequired

export default withRouter(LinkButton)

Then import the component:

import LinkButton from '/components/LinkButton'

Use the component:

<LinkButton to='/path/to/page'>Push My Buttons!</LinkButton>

If you need an onClick method:

  onClick={(event) => {
    console.log('custom event here!', event)
>Push My Buttons!</LinkButton>

Update: If you're looking for another fun option made available after the above was written, check out this useRouter hook.

Related Query

More Query from same tag