Skip to content

Adding links

Now that we have a site logo in the navigation bar, let’s add some links to pages around the site.

Traditionally, in a React app, you would use an a tag to create a link to another page.

However, in Remix, we use the Link component from @remix-run/react because it has several advantages:

  • It can be set to pre-fetch the linked page’s data, so the page loads faster
  • The Link component loads content without requiring a full page refresh
  • It can incorporate “nested routes”, where a parent route can load data for a child route (we will cover this in a later tutorial)

Let’s start by adding a Link to the logo in the navigation bar. This will link back to the home page of the site.

Firstly, let’s import the Link component from @remix-run/react:

app/components/organisms/HeaderWithSearch.tsx
import { Link, useMatches } from '@remix-run/react'
import { SearchBar } from '../molecules/SearchBar'
import LoginOrUserDropdown from './LoginOrUserDropdown'
import logo from '~/assets/png/epic-news-logo.png'

Next, let’s wrap the logo and site title inside this Link component:

app/components/organisms/HeaderWithSearch.tsx
4 collapsed lines
import { Link, useMatches } from '@remix-run/react'
import { SearchBar } from '../molecules/SearchBar'
import LoginOrUserDropdown from './LoginOrUserDropdown'
import logo from '~/assets/png/epic-news-logo.png'
export default function HeaderWithSearch() {
const matches = useMatches()
const isOnSearchPage = matches.find(m => m.id === 'routes/users+/index')
const searchBar = isOnSearchPage ? null : <SearchBar status="idle" />
return (
<header className="dark:bg-dark-primary/10 bg-primary/10 py-6">
<nav className="container flex flex-wrap items-center justify-between gap-4 sm:flex-nowrap md:gap-8">
<Link to="/">
<div className="flex items-center gap-4">
<img src={logo} alt="Epic News Logo" className="w-16" />
<span className="text-sm text-foreground">Epic News</span>
</div>
</Link>
7 collapsed lines
<div className="ml-auto hidden max-w-sm flex-1 sm:block">
{searchBar}
</div>
<div className="flex items-center gap-10">
<LoginOrUserDropdown />
</div>
<div className="block w-full sm:hidden">{searchBar}</div>
</nav>
</header>
)
}

Now that we’ve added links and a logo to the navigation bar, let’s customise the footer.

If you’ve been following along with the Epic News project, you’ll have the FooterMenuRight component from the app/components/organisms/Footer/FooterMenuRight.tsx file:

Footer menu right start

In this tutorial, we have:

  • Learned about the Remix Link component
  • Added a link to the home page in the navigation bar
  • Added a link to the ‘News’ page in the navigation bar
  • Customised the footer with links, a site logo and a copyright message

In the next tutorial, we will explore custom components included with the Epic News starter project.

We will explore how you can use them ‘out of the box’ to create rich user experiences quickly on your site, and how to customise them to suit your needs.