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 4 Basics Navigating, Nesting and Redirecting Routes Redirecting a Route

Erik L
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Erik L
Full Stack JavaScript Techdegree Graduate 19,470 Points

Redirect does not work after clicking on About link

When I click on the about link and then click on courses, I get a black page this is my code

import React from 'react';
import { Route, NavLink, Redirect } from 'react-router-dom'; //import Route to use route path and NavLink to link the routes


//Add components from courses folder in order to have access to them
import HTML from './courses/HTML';
import CSS from './courses/CSS';
import JavaScript from './courses/JavaScript';

const Courses = () => (

  <div className="main-content courses">
    <div className="course-header group">
      <h2>Courses</h2> 
      <ul className="course-nav">
      {/*use nav link to redirect  */}
        <li><NavLink to='/courses/html'>HTML</NavLink></li>
        <li><NavLink to='/courses/css'>CSS</NavLink></li>
        <li><NavLink to='/courses/javascript'>JavaScript</NavLink></li>
      </ul>
    </div>
    {/*Use routes to define routes for courses*/}
    <Route exact path="/courses" render={ () => <Redirect to="/courses/html" /> } />
    <Route path="/courses/html" component={HTML} />
    <Route path="/courses/css" component={CSS} />
    <Route path="/courses/javascript" component={JavaScript} />
  </div>

);

export default Courses;

1 Answer

Hi Erik, can you post the code in your App.js? I just replaced the code you posted with the one I have after looking through it without finding any issue with it. It worked as I expected on mine. But I will like to see your App.js file if you are still having this issue.