in react-router-dom-v6 how to pass props in navigate()? [duplicate]

I think you have to pass the state object also https://reach.tech/router/api/useNavigate

If you need to navigate programmatically (like after a form submits), this hook gives you an API to do so with a signature like this:

navigate(to, { state={}, replace=false })

This API requires a hook-compatible version of React.

import { useNavigate } from "@reach/router"

const AnalyticTracker = (props) => {
  const navigate = useNavigate();

  return (
    <form onSubmit={() => navigate('/something', { replace: true, state: {} })}>
      {...}
    </form>
  )
)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top