React-router-dom: Link 编译失败

React-router-dom: Link failed to compile

我正在使用 create-react-app 并面临 react-router-dom 的问题。问题是当我尝试使用 LinkNavLink 组件时出现此错误:

例如 RouterRoute 组件来自 react-router-dom 工作正常。

package.json

{
  "name": "pmboard-gui-bp3",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@blueprintjs/core": "^3.28.2",
    "@blueprintjs/datetime": "^3.18.2",
    "@blueprintjs/docs-theme": "^3.6.1",
    "@blueprintjs/select": "^3.13.3",
    "@blueprintjs/table": "^3.8.9",
    "@material-ui/icons": "^4.9.1",
    "axios": "^0.19.2",
    "babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
    "chart.js": "^2.9.3",
    "chartjs-plugin-annotation": "^0.5.7",
    "dotenv": "^8.2.0",
    "file-saver": "^2.0.2",
    "formik": "^1.5.8",
    "history": "^4.10.1",
    "moment": "^2.26.0",
    "node-sass": "^4.14.1",
    "prop-types": "^15.7.2",
    "quill": "^1.3.7",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-helmet": "^6.1.0",
    "react-quill": "^1.3.5",
    "react-redux": "^7.2.0",
    "react-rnd": "^10.1.10",
    "react-router-dom": "^5.2.0",
    "react-router-redux": "^4.0.8",
    "react-scripts": "3.0.1",
    "redux": "^4.0.5",
    "redux-createreducer": "^2.0.0",
    "redux-saga": "^1.1.3",
    "yup": "^0.27.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ]
  },
  "devDependencies": {
    "classnames": "^2.2.6",
    "enzyme": "^3.11.0",
    "enzyme-adapter-react-16": "^1.15.2",
    "prop-types": "^15.7.2",
    "redux-logger": "^3.0.6"
  }
}

我尝试删除 node_modules 并重新安装 -> 没用。

有什么想法吗? 如有必要,我会提供任何信息。

非常感谢您。

将导入 Link 从 react-router-dom/modules/Link 更改为 import {Link} from "react-router-dom"; 解决了问题。

即使我建议使用 "react-router-dom" 中的 NavLink;使用 Link 时,您可能会遇到一些问题。推荐使用 NavLink.