(React Navigation 5): 无法读取未定义的 属性 'replace'

(React Navigation 5): Cannot read property 'replace' of undefined

我使用版本 5 React Navigation。

根据 React Navigation documentation 我使用 replace 如下

import { StackActions } from '@react-navigation/native';

navigation.dispatch(
  StackActions.replace('Profile', {
    user: 'jane',
  })
);

但是我得到以下错误

Cannot read property 'replace' of undefined

只需更改StackActions导入源

import { StackActions } from "@react-navigation/routers/src/StackRouter";