Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Here is the index.html code

<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>

Here are the screen shots.. enter image description here

enter image description here

like image 362
Abdul Moiz Avatar asked Nov 22 '25 12:11

Abdul Moiz


2 Answers

I am using the react router 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.

import { BrowserRouter, Route, Switch } from 'react-router-dom';

<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.

like image 187
Abdul Moiz Avatar answered Nov 25 '25 00:11

Abdul Moiz


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.

I found this answer : https://stackoverflow.com/a/50657757/7867822

Basically changing <BrowserRouter/> to <HashRouter/> worked for me.

like image 32
Anurag Srivastava Avatar answered Nov 25 '25 01:11

Anurag Srivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!