Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby button onClick use Link functionality

Tags:

html

gatsby

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>
like image 349
Kyle Sharp Avatar asked Sep 08 '25 11:09

Kyle Sharp


1 Answers

import navigate

import { navigate } from "gatsby"

then in your button will be

<button onClick={()=>{navigate("/page")}}>Page button</button>
like image 196
Besufkad Menji Avatar answered Sep 10 '25 00:09

Besufkad Menji