小编HnM*_*M97的帖子

如何更改创建反应应用程序的基本网址?

我正在使用react-router-dom和create-react-app。

运行脚本yarn start,它以http://localhost:3000/(myprojectname),而不是开头http://localhost:3000/

当使用react-router-dom进行路由时,我必须myprojectname从url中删除,然后添加页面路由。

项目的初始设置好像有问题,

我该如何开始http://localhost:3000/


添加package.json、路由器代码。

包.json:

{
  "name": "cau-burger-online-order-system",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-router-dom": "^5.3.2",
    "@types/styled-components": "^5.1.16",
    "axios": "^0.24.0",
    "bootstrap": "^5.1.3",
    "brace-expansion": "^2.0.1",
    "gh-pages": "^3.2.3",
    "prettier": "^2.5.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "5.3.0",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.3",
    "typescript": "^4.1.2",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": …
Run Code Online (Sandbox Code Playgroud)

reactjs create-react-app react-router-dom

9
推荐指数
2
解决办法
4万
查看次数