我用 React 和 React Router 构建了一个 SPA。我也在使用https://github.com/facebookincubator/create-react-app,因为它是一个非常简单的应用程序。当我使用 webpack 进行开发时,我可以很好地看到页面。但是,在我使用npm run build
from为生产构建后,我create-react-app
通常会获得 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>