Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code is deployed, but page is blank #3

Closed
adjieindrawan opened this issue May 17, 2018 · 38 comments
Closed

Code is deployed, but page is blank #3

adjieindrawan opened this issue May 17, 2018 · 38 comments
Labels
react-router App uses React Router

Comments

@adjieindrawan
Copy link

adjieindrawan commented May 17, 2018

Useful package, i already follow you instruction. But i got blank page

node -v
v9.7.1

npm -v
6.0.1

create-react-app --version
1.5.2
@gitname
Copy link
Owner

gitname commented May 19, 2018

Hi @indrawanadjie, thanks for providing your Node.js, NPM, and CRA version numbers. I haven't tested the process with such recent versions of any of those things.

Before I setup a system with those version in an attempt to reproduce the behavior you reported, will you post (1) the contents of your package.json file and (2) a copy/paste of the messages that appear on the console when you follow the react-gh-pages instructions?

I would like to examine both of those things, to look for clues as to what the underlying problem is.

@adjieindrawan
Copy link
Author

adjieindrawan commented May 24, 2018

Hi @gitname thanks for your reply.

  1. Here my package.json:
{
  "name": "pimol_fb",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://fit-dev.github.io/pimol-fb-react/",
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.0-14",
    "@fortawesome/free-brands-svg-icons": "^5.1.0-11",
    "@fortawesome/free-solid-svg-icons": "^5.1.0-11",
    "@fortawesome/react-fontawesome": "^0.1.0-10",
    "animate.css": "^3.6.1",
    "bootstrap": "^4.1.1",
    "hover.css": "^2.3.1",
    "react": "^16.3.2",
    "react-dom": "^16.3.2",
    "react-rangeslider": "^2.2.0",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.4",
    "react-slick": "^0.23.1",
    "reactstrap": "^6.0.1",
    "slick-carousel": "^1.8.1",
    "webfontloader": "^1.6.28",
    "wowjs": "^1.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "lint": "eslint src/",
    "lint:fix": "eslint src/ --fix",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.3",
    "eslint": "^4.19.1",
    "eslint-config-react-app": "^2.1.0",
    "eslint-plugin-flowtype": "^2.46.3",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-prettier": "^2.6.0",
    "eslint-plugin-react": "^7.7.0",
    "gh-pages": "^1.1.0",
    "prettier": "1.12.1"
  }
}
  1. Console log only show: Slow network is detected. See https://www.chromestatus.com/feature/5636954674692096 for more details. Fallback font will be used while loading: https://fonts.gstatic.com/s/poppins/v5/pxiByp8kv8JHgFVrLCz7Z1xlFQ.woff2

Result only display favicon and title on top. Site link here: https://fit-dev.github.io/pimol-fb-react/

Thank you..

@ghost
Copy link

ghost commented Jun 24, 2018

Maybe it won't work if you have it private ?

@gitname
Copy link
Owner

gitname commented Jun 24, 2018

Hi @indrawanadjie,

Thanks for providing all the information I requested.

I visited the URL you provided (labeled "site link" in your previous comment) and examined it using the React Developer Tools extension for Google Chrome.

I saw that, in addition to the Favicon and Page Title, there are, indeed, some React elements on the page. One is shown in the screenshot below. For that reason, I think the deployment process worked (i.e. GitHub Pages is serving a built version of your app).

image

Here's what I think is happening:

I think there is something in your app, itself, that is causing it to not appear when hosted on GitHub Pages.

For example, I noticed your app uses React Router.

GitHub Pages serves your app from a non-root folder (i.e. username.github.io/repo-name/) as opposed to from a root folder (i.e. username.github.io/).

I wonder whether React Router does not consider your app's URL as a match for any of the routes defined in your app. For example, if you define a route using <Route exact path="/" component={SomeComponent} />, React Router will see that / and /repo-name/ do not match exactly and will, thus, not render the component.

I recommend you look into the basename prop of the BrowserRouter component.

@gitname
Copy link
Owner

gitname commented Jun 24, 2018

Hi @dangpro-1210, the deployment process has worked for me with both public and private GitHub repos. I appreciate you bringing up that detail, though, just in case.

@gitname gitname changed the title Already follow the Instruction, but result got blank page. Code is deployed, but page is blank Jun 24, 2018
@gitname
Copy link
Owner

gitname commented Jun 30, 2018

I will close this Issue because I think the issue lies in the app's configuration of React Router, not in the deployment process.

@indrawanadjie, did you add the basename prop to the BrowserRouter component? If so, did that fix the "Page is blank" issue? As an experiment, I suggest you deploy an app that lacks React Router, observe the behavior of the app (i.e. check whether the page is blank), then add React Router to the app, deploy the app again, and observe the new behavior of the app (i.e. check whether the page is blank).

@gitname gitname closed this as completed Jun 30, 2018
@gitname gitname added the react-router App uses React Router label Jun 30, 2018
@MohammedFaragallah
Copy link

same here for a few minutes then it loaded with my 404 after heading home works fine I think adding basename prop to the BrowserRouter will solve landing on 404. thanks @gitname

@rafalfaro18
Copy link

In my case it was a typo on the homepage URI on package.json make sure to copy the URI from the browser to be sure that it's correct.

@tylerreece22
Copy link

Solved it for me too! Woohoo! Thank you!

@Tobibur
Copy link

Tobibur commented Jun 28, 2019

Yes!! Thank you for this! It worked for me with the basename prop of the BrowserRouter component. 😄

@Tirthnp
Copy link

Tirthnp commented Jul 8, 2019

Adding BrowserRouter basename ="/directory-name"> worked for me. Thank You!!

@kumar303
Copy link

kumar303 commented Sep 14, 2019

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

@nuri-engin
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

That fixed my issue as well. Thanks.

@frontendjorge
Copy link

</BrowserRouter>

Well. Not always works. In my case I preferred to put the basename with the name or variable of subfolder. With your solution when you reload the webpage takes de last path and add the same again path.

@cadenzah
Copy link

cadenzah commented Jan 1, 2020

All users using Github Page to deploy their react-router based app should read this issue!

@bonniesimon
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

This fixed my issue, Thanks a lot💛

@manjunkoh
Copy link

I dont know if anyone else is still having this issue, but I was having trouble hosting my website on /docs folder and i made the env.public part global and it somehow worked for me. like this:
{${process.env.PUBLIC_URL}/}

Also if anyone is doing the same way as I am like hosting or debugging on docs folder you gotta follow the exact steps:

  1. disable github pages to none
  2. empty the docs folder then push
  3. enable github pages using docs again
  4. build on docs again then push

doing these worked for me.

@jAbusama
Copy link

jAbusama commented Apr 13, 2020

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

This fixed my issue, Thanks a lot💛

This works for me. It helps me to get out to this issue. Thanks Bro! @bonniesimon

@KrenarMuzaqi
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

That fixed my issue as well. Thanks.

Can you help me, because i have same problem, i have only one path and my app shows blank page, where should i put this :
<BrowserRouter basename={window.location.pathname || ''}>

@larissarodr
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

Awesome. This works for me as well. Thank you!

@rohan8660
Copy link

I didnt use any router , but it still is showing blank,

site:address 👍
https://rohan8660.github.io/IEEE_GIT-Website-Contest-Let-s_React/

@EngrEli
Copy link

EngrEli commented Aug 27, 2020

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

I have different Routes but this seems to work for me as well.
Thank you good sir!!
I didn't expect that using react-router would cause a problem in deployment.

@azeemaleem149
Copy link

@kumar303 Thanks My Issue Resolved Successfully after trying 12 hours.
<BrowserRouter basename={window.location.pathname || ''}>


@soheil-74
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

this's great! tnx a lot bro...

@vehbirestelica
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

THANKSSSSSSSSSS

@limunosekai
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

Wow!!!!!!!!! Thanks a lot. It works finally

@kadirretir
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

I have more than one paths i guess that's why it doesn't work for me. How should i apply this code?

@Muhammed-Rahif
Copy link

Working fine now... Hoooo.... 🥳

DitisAlex pushed a commit to DitisAlex/SinChen that referenced this issue Jun 30, 2021
@danishalikhan688
Copy link

Since my app only has one path, I was able to get it working for both GitHub pages and local development (http://localhost:3000/) like this:

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

Awesome. This works for me as well. Thank you!

thank you so much it works for me bundle of thanks , i have use this basename attribute as well as add homepage attribute in your package.json file the deployed website url in homepage than create build it works for me

@danishalikhan688
Copy link

Add "basename" attribute in BrowserRouter like this
<BrowserRouter basename={window.location.pathname || ''}>


if still it does not work for than add homepage attribute in your package.JSON file
"homepage":"https://xyz.com/",
hopefully it will work

@shubhamjha25
Copy link

I was also facing the same problem while deploying Blogify to gh-pages.

Code was deployed and but the link when opened showed white blank page.
I was able to see the favicon and app-name on the browser tab.

The homepage was also set correctly
"homepage": "https://shubhamjha25github.io/Blogify/"

Also, I was using react-router extensively and had multiple paths like /about, /login, /register, /blogs etc.

After scraping the internet, did this little change in the BrowserRouter component

ReactDOM.render(
  <React.StrictMode>
        <BrowserRouter basename={process.env.PUBLIC_URL}>
            <App />
        </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);

i.e., added basename={process.env.PUBLIC_URL} prop to the BrowserRouter component.
It's working fine now.

FYI : process.env.PUBLIC_URL is a part of the node.js library and is a dynamically generated URL that changes based on what development mode you are in, whether you are working on your app locally, or on an actual production server like gh-pages.

@lcorn26
Copy link

lcorn26 commented Nov 9, 2021

THANK YOU this needs to be somewhere more visable

@Wasabi95
Copy link

Do you know how to preview a react project on GitHub pages? I follow the instructions here https://github.com/gitname/react-gh-pages but it did not work

@sujanmongar
Copy link

I added basename and it's not working in my case. Please need help

@ShujaShah
Copy link

<BrowserRouter basename={window.location.pathname || ''}>
  <Route exact path="/" component={Index} />
</BrowserRouter>

This one worked for me thanks :)``

@LeNikki
Copy link

LeNikki commented Aug 8, 2022

This worked for me. I have multiple pages too! Thank you so much!!

@NisargDeveloper
Copy link

Hi @indrawanadjie,

Thanks for providing all the information I requested.

I visited the URL you provided (labeled "site link" in your previous comment) and examined it using the React Developer Tools extension for Google Chrome.

I saw that, in addition to the Favicon and Page Title, there are, indeed, some React elements on the page. One is shown in the screenshot below. For that reason, I think the deployment process worked (i.e. GitHub Pages is serving a built version of your app).

image

Here's what I think is happening:

I think there is something in your app, itself, that is causing it to not appear when hosted on GitHub Pages.

For example, I noticed your app uses React Router.

GitHub Pages serves your app from a non-root folder (i.e. username.github.io/repo-name/) as opposed to from a root folder (i.e. username.github.io/).

I wonder whether React Router does not consider your app's URL as a match for any of the routes defined in your app. For example, if you define a route using <Route exact path="/" component={SomeComponent} />, React Router will see that / and /repo-name/ do not match exactly and will, thus, not render the component.

I recommend you look into the basename prop of the BrowserRouter component.

Thanks It worked for me!

@teleperformance923
Copy link

Maybe it won't work if you have it private ?
thank you it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react-router App uses React Router
Projects
None yet
Development

No branches or pull requests