Create React App builds empty document with react-router
See original GitHub issueI am using the current version of Create React App and I’m having a weird problem. I just started using react-router
and everything is working perfectly in npm start
. However, when I build the file with npm run build
, the resultant HTML is entirely blank. The #root element exists, but contains only a comment with the text react-empty: 1
.
This behavior is consistent regardless of how I set the homepage
field in package.json
, and whether I open it locally or host it on my website.
My app.js
file is as follows:
... imports ...
ReactDOM.render(
(<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="/news" component={News} />
<Route path="/current" component={Current} />
<Route path="/previous" component={Previous} />
<Route path="/about" component={About} />
<Route path="/enter" component={Enter} />
<Route path="/login" component={Login} />
<Route path="/profile" component={Profile} />
</Route>
</Router>),
document.querySelector('#root')
);
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Create React App builds empty document (blank screen) with ...
The const 'condition' in the connectScreen component is undefined. Your authentication logic then prevents the component from rendering.
Read more >Create a New React App
Create React App doesn't handle backend logic or databases; it just creates a frontend build pipeline, so you can use it with any...
Read more >React | IntelliJ IDEA Documentation - JetBrains
The recommended way to start building a new React single page application is create-react-app package, which IntelliJ IDEA downloads and runs ...
Read more >Create a React App with React Router Dom v6
Hi guys! In this post, I will be giving a complete walkthrough on how to create a React App with the help of...
Read more >How To Build A React JS Website With React Router DOM
Follow along and see how I built this data security website in React JS. We will be using a couple react packages such...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Your route definition is declared against
/
. But your app is served from/hypercomp/
. React Router doesn’t know anything about thehomepage
setting, so it can’t match the URLs.You can work around this by doing something like:
In the future, we might change it so that the app would get served from the relative path in development too, so that you’d learn about the problem earlier. See discussion in https://github.com/facebookincubator/create-react-app/issues/1582.
Hope this helps!
Also consider sharing what your mistake was. Somebody else might repeat it 😉