-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Create React App builds empty document with react-router #1617
Comments
Are you serving the build? Just opening it from the filesystem won't do. |
Oops, missed this part:
I don't know what's causing the problem. We'll need to see a hosted example to figure it out. |
Example meaning the codebase? Because what's hosted is the empty document. (https://furkleindustries.com/hypercomp) Would you prefer to look at the repository? (It's here: https://bitbucket.org/furkle/hypercomp) And I may be remembering this entirely wrong, but before I started using |
Your route definition is declared against You can work around this by doing something like: const baseUrl = process.env.PUBLIC_URL; // will be /hypercomp
ReactDOM.render(
(<Router history={browserHistory}>
<Route path={baseUrl + "/"} component={App}>
<IndexRoute component={Home} />
<Route path={baseUrl + "/news"} component={News} />
<Route path={baseUrl + "/current"} component={Current} />
<Route path={baseUrl + "/previous"} component={Previous} />
<Route path={baseUrl + "/about"} component={About} />
<Route path={baseUrl + "/enter"} component={Enter} />
<Route path={baseUrl + "/login"} component={Login} />
<Route path={baseUrl + "/profile"} component={Profile} />
</Route>
</Router>),
document.querySelector('#root')
); 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 #1582. Hope this helps! |
This works in the test build, but in the version I'm serving online, all the route links point at the root directory for the website, not the root directory of the app. Is there an easy workaround for this? Thanks for your help so far. |
You should be able to apply similar logic to your links: <Link to={`${process.env.PUBLIC_URL}/path`}>...</Link> |
Oh, duh, I have no idea why it didn't occur to me that I'd have to change the |
I have the same problem too! Did you fix it? @furkle |
@hungtn if you open a new issue we'll be more than happy to help or point you to the right documentation. |
@Timer Thanks you so much, I found that is my mistake. |
@hungtn glad to hear it got fixed! Please let us know if there's anything we can help with. 😄 |
Also consider sharing what your mistake was. Somebody else might repeat it 😉 |
@gaearon My problem is when I build: |
I 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 innpm start
. However, when I build the file withnpm run build
, the resultant HTML is entirely blank. The #root element exists, but contains only a comment with the textreact-empty: 1
.This behavior is consistent regardless of how I set the
homepage
field inpackage.json
, and whether I open it locally or host it on my website.My
app.js
file is as follows:The text was updated successfully, but these errors were encountered: