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

G H Mahimaanvita
G H Mahimaanvita
16,234 Points

Not sure what exact keyword does

    <Route path="/courses" render={() => <Redirect to="/courses/html" />} />
    <Route path="/courses/html" render={() => <HTML />} />
    <Route path="/courses/css" render={() => <CSS />} />
    <Route path="/courses/javascript" render={() => <JavaScript />} />

I did not add the 'exact' keyword in path="/courses" so I expected that even if i click the link to /courses/css or javascript I would be redirected to /courses/html

Why didn't that happen?
Moreover, even if I click the Courses link after css and javascript it doesn't redirect to html!
It works if I add the 'exact' keyword
I thought the 'exact' keyword prevents routing if the url dosent match exactly.... but dosen't it look like it's doing the opposite here?

1 Answer

I think it's because the method only works if you aren't already in a 'courses' path, otherwise it won't rerender. Actually, if you don't have 'exact' and you type in a '/courses/css' path in the browser when you aren't already in a courses path it will redirect you to '/courses/html'