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 Navigating Between Routes

Why not just use anchor tags?

What is the benefit of using link over anchor tags? Because the code below works too right?

      <li><a href="/">Home</Link></li>
      <li><a href="/about">About</Link></li>
      <li><a href="/teachers">Teachers</Link></li>
      <li><a href="/courses">Courses</Link></li>

2 Answers

Steven Parker
Steven Parker
229,732 Points

The code above would cause syntax errors due to mismatched tags. The start and end tags of each element must have the sane tag name.

But when correctly coded, a link actually renders into an anchor for the browser. But in the process elements are added to provide visual indications of the active status of the link.

Whoops I meant to change the end tags to an anchor tags as well. It seems though the link component provides extra functionality to the routes. So it makes sense to use it now.

Steven Parker
Steven Parker
229,732 Points

That wouldn't be a "benefit" if you want to add a clickable element to the page. And link tags cannot have any content, and have no end tag.