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 trialAnne Whitman
10,430 PointsNested Routes not working
I can only get my routes to work non-nesting:
<Route path='teachers' element={<Teachers />} />
<Route path='teachers/:name/:course' element={<Featured />} />
If I try nesting in <Route>
</Route>
tags:
<Route path='teachers' element={<Teachers />}>
<Route index element={<Teachers />} />
<Route path=':name/:course' element={<Featured />} />
</Route>
and try navigating to http://localhost:3000/teachers/Jane/HTML
I just get the generic teacher page. Is there something obvious I'm doing wrong?
1 Answer
Rohald van Merode
Treehouse StaffHey Anne Whitman 👋
You're super close to getting this working! The only thing you'll want to adjust from your nested snippet is removing the element
prop from the parent Route
. This is currently overwriting the nested routes.
After removing the element={<Teachers />}
everything should start working as shown in the video 😃
Hope this helps!
Anne Whitman
10,430 PointsAnne Whitman
10,430 PointsThank you so much!! I tried comparing to the video, but i must have paused it a little too early before that was removed.