2

我想将react-router软件包升级到v6. 它依赖于history包,并且在history包路线图中,文档说history.length将很快被弃用甚至删除。你可以看看https://github.com/remix-run/history/issues/689

我想知道在将软件包升级到最新版本时是否有其他替代方法可以history.length在我的代码中使用。react-router

例如,我对它的一种用法:

  import { useHistory } from 'react-router';

  const history = useHistory();

  const onGoBack = () => {
    if (history.length > 2) {
      history.goBack();
    } else {
      history.push('/portfolio');
    }
  };
4

0 回答 0