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

Peter Mingione
11,588 Pointssub nav is not working as expected
When building Descendant routes, when I click one of the sub nav buttons on the courses page, the subnav in the url does not get replaced but added to
example ...
http://localhost:3000/courses/
http://localhost:3000/courses/html/
http://localhost:3000/courses/html/css/
http://localhost:3000/courses/html/css/javascript/
I am not sure why this is happening
4 Answers

Travis Alstrand
Treehouse Project ReviewerIn React Router v6, when using <Link to="something">
or navigate("something")
, that path is relative to the current location, not the root. So if you're currently at /courses/html
and you do:
<Link to="css">CSS</Link>
It will go to /courses/html/css
.
I'd recommend trying absolute paths To avoid appending and instead replace the path, make the to prop start with a slash, like:
<Link to="/courses/css">CSS</Link>
I hope this helps, if I'm way off here please let me know

Peter Mingione
11,588 PointsThanks Travis ... that works. But the video lesson says to use the relative path. I'm just wondering why Laura is saying to build the sub nav that way. Am I missing something?

Travis Alstrand
Treehouse Project ReviewerMy apologies, I should have looked further into the video before replying. I just downloaded the project files beneath the video and ran the "END" files for this video specifically and everything is working on my end as she has it in the video. I would ensure you've got the same set as her in your files. Here's what I have, which is straight out of the project files.
App.js routes
<Routes>
<Route path="/" element={<Home />} />
<Route path="about" element={<About />} />
<Route path="teachers" element={<Teachers />} />
<Route path="courses" element={<Courses />}>
<Route path="html" element={<HTML />} />
<Route path="css" element={<CSS />} />
<Route path="javascript" element={<JavaScript />} />
</Route>
</Routes>
*Courses.js *
const Courses = () => (
<div className="main-content courses">
<div className="course-header group">
<h2>Courses</h2>
<ul className="course-nav">
<li><NavLink to='html'>HTML</NavLink></li>
<li><NavLink to='css'>CSS</NavLink></li>
<li><NavLink to='javascript'>JavaScript</NavLink></li>
</ul>
</div>
<Outlet />
</div>
);
Do you have something different in your code by chance?
Here are some things you could look out for that I can think of without seeing the code.
Is the subnav with
<NavLink to="...">
inCourses.js
, not in HTML, CSS, or JavaScript?Is
Courses.js
using<Outlet />
and not declaring its own<Routes>
?Is routing defined only once at the top-level
App.js
?

Peter Mingione
11,588 PointsHi Travis ... This is further on in the course than I have gotten to. I am looking at section 2 video 4, "Descendant and Nested Routing". I am trying to build a descendant NavLinks the way Laura does in this video.