应用程序在节点服务器中运行良好,但我在 Apache 服务器中得到空白页面,即使我使用了绝对路径。
这是index.html代码
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="/manifest.json">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<title>React App</title>
<link href="./static/css/main.0778317d.css" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="text/javascript" src="./static/js/main.1b4d826e.js"></script>
</body>
最佳答案
我正在使用 react router 4。所以当我使用 Router 时,它会产生问题并且无法使用绝对路径。而不是 Router 使用 BrowserRouter 并使用 basename 作为我复制项目构建的文件夹商店。
从 'react-router-dom' 导入 { BrowserRouter, Route, Switch };
<BrowserRouter history={history} basename="/shop/">
<div>
<Switch>
<Route exact path="/" component={App} />
<Route path="/cart" component={Cart} />
<PublicRoute path="/login" component={LoginPage} />
<PrivateRoute path="/dashboard" component={DashBoardPage} />
<PrivateRoute path="/checkout" component={checkOut} />
<PrivateRoute path="/favourite" component={favourite} />
<PrivateRoute
path="/payment_Information"
component={PaymentInformation}
/>
<Route path="/product_details/:pid" component={ProductDeatils} />
<Route path="*" compononent="NotFound" />
</Switch>
</div>
</BrowserRouter>
并在 package.json 文件 "homepage": "/shop" 中创建路径。
关于javascript - 为什么当我在 Apache 上运行我的 react 构建时......只出现空白页面..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52369027/