toy toy - 9 months ago 84
React JSX Question

Seeing empty page after deployed to S3 with React Route

I build a SPA with React and React Router. I'm also using as it's a really simple application. When I'm developing using webpack I can see the page fine. However, after I build for production using

npm run build
I get HTML file and css and js normally. I uploaded everything to S3 but when I go to the page I only get blank page

And this is what I'm seeing

<!-- react-empty: 1 -->

I'm guessing it's like this because S3 is default to
and I cannot change that. And React Router doesn't know how to deal with
but I also have
root as the default but I'm still seeing a blank page. Not sure how to fix this issue?

Here's my Router

<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="question2" component={Question2} />
<Route path="question3" component={Question3} />
<Route path="thankyou" component={Thankyou} />

And this is the template
use and it's working fine on development.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
<title>React App</title>
<div id="root"></div>
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.

Answer Source

You are attempting to use a browserHistory on a static web page. You should use a hashHistory for static pages.