How can I change the page whitout react hoocks?

54 Views Asked by At

How can navigate?

import ButtonLogReg from "../components/ButtonLogReg"
import { Link } from 'react-router-dom'
import { useContext } from 'react'
import Context from '../components/Context'
import { useNavigate } from 'react-router-dom'

function Launcher() {
    log.info('Home -> render')

    const { showAlert } = useContext(Context)

    const handler = event => {

      event.preventDefault()
      try(
         asyncFunction()
         )catch(error)
    }

    return <main>
        <nav>
            <h2 >Go?</h2>
            <Link to="/Mypath>"<ButtonLogReg onClick={handler}>READY</ButtonLogReg></Link>
            <Link to="/"><h2>Back</h2></Link>
        </nav>
    </main>
}


export default Launcher

Hi everybody, I try to navigate at /Mypath, but i can't do this whit a , how can I do this?

1

There are 1 best solutions below

0
On

Hope you have setup the route in App.js, then this might help you:

import ButtonLogReg from "../components/ButtonLogReg"
import { useContext } from 'react'
import Context from '../components/Context'
import { useNavigate } from 'react-router-dom'

function Launcher() {
    log.info('Home -> render')

    const { showAlert } = useContext(Context)

    const handler = event => {

        event.preventDefault()
        try(
            asyncFunction()
        )catch (error)
        }

    const navigate = useNavigate();

    return <main>
        <nav>
            <h2 >Go?</h2>
            <ButtonLogReg onClick={() => navigate("/Mypath")} >READY</ButtonLogReg>
            <h2 onClick={() => navigate("/")} >Back</h2>
        </nav>
    </main>
}


export default Launcher