【问题标题】:Attempted import error: 'Outlet' is not exported from 'react-router-dom尝试导入错误:“Outlet”未从“react-router-dom”导出
【发布时间】:2021-04-14 18:56:32
【问题描述】:

我收到此错误尝试导入错误:'Outlet' 未从'react-router-dom 导出

如果我评论 Outlet 它会抛出 Attempted import error: 'Switch' is notexported from 'react-router-dom

我的 package.json 是

{
  "name": "react-shoe-store-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.11.2",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "axios": "^0.21.1",
    "history": "^5.0.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router": "^6.0.0-beta.0",
    "react-router-dom": "^6.0.0-beta.0",
    "react-scripts": "4.0.1",
    "react-slick": "^0.27.13",
    "slick-carousel": "^1.8.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我已经安装了 react-router-dom v6 但我无法配置这个错误

【问题讨论】:

  • 您需要显示导入这些实体的代码,也无需显示所有 package.json。只需相关库的版本就足够了。我认为它有帮助。另外,我假设您已经运行 npm install 并确保下载了依赖项。

标签: javascript reactjs react-router-dom


【解决方案1】:

我找不到任何关于 Outlet 的信息,但 Switch 是从 react-router 导出的,而不是从 react-router-domsee here 导出的

import { Switch } from "react-router";

【讨论】:

    猜你喜欢
    • 2020-11-01
    • 2020-04-26
    • 2020-02-12
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2022-01-21
    相关资源
    最近更新 更多