5

I implement page navigations with react-router. When moving from B to A after moving from A to B, needs page back behavior. Therefore, I wrote bellow.

import { useHistory } from 'react-router';

const history = useHisotry()

history.goBack();

It works well. But I have my doubts about it. I can use window.hisotry.back() instead of useHisotry() back.

Why use useHistory goBack function instead of window history back function?

wato9902
  • 619
  • 7
  • 18
  • The answer here https://stackoverflow.com/a/54540244 might explain although the question relates to react-router-dom, not react-router. But I guess it is pretty much same since react-router-dom is based on react-router. – JunKim Feb 14 '22 at 05:12

0 Answers0