Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Router Basics Going Further with Routes Displaying 404 Error Routes

Giuseppe Barbera
Giuseppe Barbera
1,933 Points

index.html output blank page

how can se the output in index.html ? in localhost all works fine, but index.html i see only the menu, no router etc etc

3 Answers

Jonathan Dewitt
Jonathan Dewitt
8,101 Points

To use this with current versions of react-router (v4) you need to use a switch element. This is how I got mine to work:

// Routes
const routes = (
    <Router history={History}>
        <App>
            <Switch>
                <Route exact path="/" component={Home} />
                <Route path="/about" component={About} />
                <Route path="/courses" component={Courses} />
                <Route path="/teachers" component={Teachers} />
                <Route component={NotFound} />
            </Switch>
        </App>
    </Router>
);

To see errors, press Cmmd+Shift+i on a Mac and Ctrl-Shift-i on Windows. I recommend doing this on Google Chrome or Firefox since I think you have to install things when using other browsers.

Giuseppe Barbera
Giuseppe Barbera
1,933 Points

No error in console, in i launch npm start and localhost all work fine.. but if open the html Only page blank..the bundle.js its compiled...

Can you show your HTML?