Gatsby button onClick use Link functionality

4.8k Views Asked by At

I want to use Gatsby's Link functionality inside a button. I am doing this cause I am having an easier time formatting the button to look like what I want as opposed messing with the Link formatting.

This is my old code

import { Link } from "gatsby"
<button>
    <Link to="/event-details">Details</Link>
</button>

This is what what I am trying to get to work.

import { Link } from "gatsby"
<button onClick:'Link to = /page'>Page button</button>
1

There are 1 best solutions below

1
On BEST ANSWER

import navigate

import { navigate } from "gatsby"

then in your button will be

<button onClick={()=>{navigate("/page")}}>Page button</button>