Skip to content
Discussion options

You must be logged in to vote

The best way is to don't use a button and instead use a link

import { Link } from "@remix-run/react"
// ...
return <Link to="/a-link">Click me</Link>

If for some reason you need a button you can do this

import { useNavigate } from "@remix-run/react"
// ...
let navigate = useNavigate()
return <button type="button" onClick={() => navigate("/a-link")}>Click me</button>

In my experience, if you find yourself needing to navigate after a button click, most of the time is because you need to do something before the navigation, and most of the time you can move whatever you're doing to an action function in the server, return return a redirect from there and wrap the button in a Form that submits…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sergiodxa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants