“Botão Chrome Back Button Click Event React” Respostas de código

Se reagir de volta

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


const [ locationKeys, setLocationKeys ] = useState([])
const history = useHistory()

useEffect(() => {
  return history.listen(location => {
    if (history.action === 'PUSH') {
      setLocationKeys([ location.key ])
    }

    if (history.action === 'POP') {
      if (locationKeys[1] === location.key) {
        setLocationKeys(([ _, ...keys ]) => keys)

        // Handle forward event

      } else {
        setLocationKeys((keys) => [ location.key, ...keys ])

        // Handle back event

      }
    }
  })
}, [ locationKeys, ])
Wide-eyed Weevil

Botão Chrome Back Button Click Event React

const {history} = useRouter();
  useEffect(() => {
    return () => {
      // && history.location.pathname === "any specific path")
      if (history.action === "POP") {
        history.replace(history.location.pathname, /* the new state */);
      }
    };
  }, [history])
Tense Thrush

Respostas semelhantes a “Botão Chrome Back Button Click Event React”

Perguntas semelhantes a “Botão Chrome Back Button Click Event React”

Mais respostas relacionadas para “Botão Chrome Back Button Click Event React” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código