簡體   English   中英

npm 運行構建后反應空白頁或404頁,問題出在哪里?

[英]React blank page or 404 page after npm run build, Where did the problem come from?

在 npm 運行 build(react) 之后,我的 index.html 顯示一個空白頁面。

首先,我試過這個。

  1. 添加package.json
homepage : "./" or "." or "absolute file PATH"

而我的 package.json 是...

{
  "name": "client",
  "homepage": "./",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "axios": "^0.21.4",
    "bootstrap": "^5.1.0",
    "dotenv": "^10.0.0",
    "html-react-parser": "^1.3.0",
    "http-proxy-middleware": "^2.0.1",
    "quill": "^1.3.7",
    "react": "^17.0.2",
    "react-bootstrap": "^2.0.0-beta.6",
    "react-dom": "^17.0.2",
    "react-ga": "^3.3.0",
    "react-html-parser": "^2.0.2",
    "react-icons": "^4.2.0",
    "react-kakao-maps-sdk": "^1.0.3",
    "react-loading-skeleton": "^3.0.1",
    "react-quill": "^1.3.5",
    "react-redux": "^7.2.5",
    "react-router-dom": "^5.3.0",
    "react-scripts": "4.0.3",
    "react-use-clipboard": "^1.0.7",
    "redux": "^4.1.1",
    "redux-devtools-extension": "^2.13.9",
    "redux-persist": "^6.0.0",
    "redux-promise": "^0.6.0",
    "redux-thunk": "^2.3.0",
    "use-react-router": "^1.0.7",
    "web-vitals": "^1.1.2"
  },
  "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"
    ]
  }
}

我的 app.js 文件是...

import React, { useEffect } from "react";
import { Switch, Route, BrowserRouter } from "react-router-dom";

//import some components omitted

const App = () => {
// some logical code
return (
        <BrowserRouter history={history}>

            <Switch>
                <Route path="/contact" component={Contact} exact />
                <Route path="/withdrawal" component={Withdrawal} exact />
                
                {* and some Route code omitted *}

                <Route path="*" component={ErrPage} />
            </Switch>
        </BrowserRouter>
    );
};

export default App;

我的代碼有什么問題? 或者我應該做更多的設置?

構建應用程序后,您需要打開“構建”文件夾...然后使用編輯器打開 index.html... 之后您需要搜索具有“靜態”的源,例如:

所以你需要在小節之前放一個點,比如這個例子:

您需要在此檔案中放入所有 static 源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM