Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
How to redirect in react if the user logged in

Well before writing this question i have searched internet Basically it shows 3 solution i tried all they seems to be outdated

1. using history.push('/')

The problem i am facing with this method is that browser saying who the hell is push i dont know what she is to debug i try to console history i find it is undefined i have seen in the answer they

I am just copying their answers

import { useHistory } from "react-router-dom"

function HomeButton() {
  let history = useHistory()

  function handleClick() {
    history.push("/home")
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  )
}

but this does not work because useHistory import error it is outdated the other answers also is not usable like done with redirect again having import error

Please suggest me a good way to do this

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

history is depreciated since react-router version 6+, if you want to migrate then follow this link.

If you however freshly installed version 6+ then you can use useNavigate

import { useNavigate } from "react-router-dom";

function HomeButton() {
  let navigate = useNavigate()

  function handleClick() {
     navigate("/home")
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  )
}

more on the topic here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!