我想将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');
}
};