【发布时间】:2017-04-02 22:03:42
【问题描述】:
我用 React 和 React Router 构建了一个 SPA。我也在使用https://github.com/facebookincubator/create-react-app,因为它是一个非常简单的应用程序。当我使用 webpack 开发时,我可以很好地看到页面。但是,在我使用来自create-react-app 的npm run build 构建生产后,我通常会获得HTML 文件和css 和js。我将所有内容上传到 S3,但是当我转到该页面时,我只得到空白页面
这就是我所看到的
<!-- react-empty: 1 -->
我猜是这样的,因为 S3 默认为 index.html,我无法更改。 React Router 不知道如何处理index.html,但我也有/ root 作为默认值,但我仍然看到一个空白页。不确定如何解决此问题?
这是我的路由器
ReactDOM.render(
<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} />
</Route>
</Router>,
document.getElementById('root')
);
这是creawte-react-app 使用的模板,它在开发中运行良好。
<!doctype html>
<html lang="en">
<head>
<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>
</head>
<body>
<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`.
-->
</body>
</html>
【问题讨论】:
标签: javascript html reactjs amazon-s3 react-router