Javascript 为什么当我在Apache上运行react构建时…只会出现一个空白页。。?
应用程序在节点服务器上运行良好,但我在Apache服务器上得到了空白页面,尽管我使用了绝对路径 下面是index.html代码Javascript 为什么当我在Apache上运行react构建时…只会出现一个空白页。。?,javascript,reactjs,apache,Javascript,Reactjs,Apache,应用程序在节点服务器上运行良好,但我在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"&g
<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>
反应应用程序
您需要启用JavaScript才能运行此应用程序。
以下是屏幕截图。。
我正在使用反应路由器4。因此,当我使用路由器时,它会产生问题,无法使用绝对路径。使用BrowserRouter代替Router,并将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文件“主页”:“/shop”中创建路径。我无法使用React Router v4让我的应用程序在Apache主机上运行,即使尝试了@Abdul Moiz提到的步骤 我找到了这个答案: 基本上把
改成
对我来说很有效