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

Losing Redirects

I don't understand how we lost the Redirect when clicking on on the main Courses link in the header. My understanding is that click is handled by the Header component which has a Route component that matches /courses and then loads our Courses component which has a Redirect to /courses/html. I don't understand why we need a Route component to /courses in the Courses component file. Isn't that Courses link handled by the Header component that has a Route to /courses?

1 Answer

Adam McGrade
Adam McGrade
26,333 Points

My understanding is that once the route hits "/courses", the routing is controlled by the Courses component.

The Redirect component inside the Courses component is matching the "/courses" part of the "/courses/html", "/courses/css", "/courses/javascript" routes and attempting to redirect to "/courses/html" every time there is a match.

To avoid this behaviour, we created a Route component with the "exact" property set to "/courses" that returns the Redirect component to ensure that the redirect only occurs on a route that is an exact match for "/courses".