[英]Why is that when i run my react build on Apache...Just blank page appears..?
app is working fine in node server but i am getting blank page in Apache server even though i used absolute path.应用程序在节点服务器中运行良好,但即使我使用了绝对路径,我在 Apache 服务器中也出现了空白页面。
Here is the index.html code这是 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>
I am using the react router 4 .我正在使用反应路由器 4 。 so when i used Router it create problems and not working with absolute paths.因此,当我使用路由器时,它会产生问题并且无法使用绝对路径。 instead of Router using BrowserRouter and used basename for folder shop where i copied the build of my project.而不是Router使用BrowserRouter并使用basename用于文件夹商店,我在其中复制了我的项目的构建。
import { BrowserRouter, Route, Switch } from 'react-router-dom';从'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>
and in package.json file "homepage": "/shop" to create paths.并在package.json文件"homepage": "/shop"中创建路径。
I was not able to get my app using React Router v4 to work on Apache hosting, even after trying the steps mentioned by @Abdul Moiz.即使尝试了@Abdul Moiz 提到的步骤,我也无法使用 React Router v4 使我的应用程序在 Apache 托管上工作。
I found this answer : https://stackoverflow.com/a/50657757/7867822我找到了这个答案: https : //stackoverflow.com/a/50657757/7867822
Basically changing <BrowserRouter/>
to <HashRouter/>
worked for me.基本上将<BrowserRouter/>
更改为<HashRouter/>
对我<HashRouter/>
。
If the website is hosted on http://namweb.com/NamFdr如果网站托管在http://namweb.com/NamFdr
Add the Folder name "NamFdr" in the below config :在以下配置中添加文件夹名称“NamFdr”:
|+> Add in package.json |+> 在 package.json 中添加
"homepage": "/NamFdr",
|+> Add Router basename config in index.js |+> 在 index.js 中添加路由器基名配置
ReactDOM.render(
<BrowserRouter basename='/blocal'>
<App />
</BrowserRouter>,
document.getElementById('root')
)
[Or] Add Router basename config in app.js [或] 在 app.js 中添加 Router basename 配置
import { BrowserRouter, Route, Switch } from 'react-router-dom';
-------------------------
<BrowserRouter basename="/NamFdr/">
<Switch>
<Route exact path="/" component={App} />
</Switch>
</BrowserRouter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.