0

I have a React app I've build using create-react-app, which uses react-router. When I open the test development view using npm start, everything works perfectly fine. However, when I build the app -- regardless of what I set the homepage field in package.json to -- all I get is a #root div with a react-empty: 1 comment.

My index.js component looks like so:

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')
 );

Please let me know if you need to see any more code in order to figure out what's going on. Just to reiterate -- there are no errors showing up whatsoever, either in npm test or the build copy of the app.

5
  • What do you mean by "homepage field in package.json"? Why you added such a field? Commented Feb 20, 2017 at 0:39
  • @kbariotis Because that's how create-react-app works with regards to assets stored at relative paths. Are you familar with the technology I'm talking about? Commented Feb 20, 2017 at 0:57
  • 1
    @kbariotis as per documentation: By default, Create React App produces a build assuming your app is hosted at the server root. To override this, specify the homepage in your package.json, for example: "homepage": "http://mywebsite.com/relativepath" This will let Create React App correctly infer the root path to use in the generated HTML file. Commented Feb 20, 2017 at 0:58
  • I see, but i don't see how that could affect your app. Any other modification you did? Commented Feb 20, 2017 at 1:26
  • Because if it's not set correctly it won't be able to find the script bundle, which means no react app. And no. Commented Feb 20, 2017 at 1:30

1 Answer 1

1

This is a problem with relative path as homepage in package.json and definition of routes.

Router will render something like <!-- react-empty: 1 --> if it has to render say null.

You've set set Route path="/" where this should match the relative path in homepage.

You could change this to

<Route path=process.env.PUBLIC_URL component={App}>

This would take what you've given as homepage in package.json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.