DEV Community

prateekshaweb
prateekshaweb

Posted on • Originally published at prateeksha.com

React Router Basics: Multi-Page Navigation for a Brochure Website

Hook — why this matters

If you’re building a simple brochure website in React, you want crisp, URL-driven navigation without sacrificing the speed and statefulness of a single-page app. React Router gives you multi-page-like navigation with no full page reloads, letting visitors move between Home, About, Services, and Contact pages quickly and predictably.

This article explains the practical why and how: when to use React Router, what the minimal setup looks like, and a handful of implementation tips to keep your site maintainable and deployable.

When to use React Router for a brochure site

A brochure site is usually a small collection of static-ish pages meant to inform visitors. Even for a 3–6 page site, React Router is useful because it:

  • Keeps navigation snappy (no full reloads).
  • Maps readable URLs to components.
  • Makes your layout and navigation reusable.
  • Keeps the door open for future expansion (nested pages, sections).

If you prefer a component-first architecture and plan to add small interactive features later, Router is a future-proof choice.

The minimal setup (conceptually)

You don’t need a lot to get multi-page navigation working:

  • Install react-router-dom in your project.
  • Wrap your app in a BrowserRouter so routing features are available.
  • Define a Routes container and several Route entries that map path strings to components.
  • Use Link or NavLink elements instead of native anchor tags for internal navigation.

Think of BrowserRouter as the wiring, Routes/Route as the map, and NavLink/Link as the clickable GPS that updates the URL without leaving the page.

Core concepts (plain language)

  • BrowserRouter: the router provider that listens to the browser URL and manages history.
  • Routes: a container that chooses which route to render based on the current path.
  • Route: a single path => component mapping, like "/about" => AboutPage.
  • Link / NavLink: replacements for anchor tags that navigate without reloading; NavLink can automatically mark the active link.
  • Outlet: a placeholder inside a parent layout where nested child routes render.

You don’t need to memorize API names, but understand the roles: provider, router map, link helpers, and an outlet for nested content.

Quick checklist before you code

  • Node and npm installed; project created (Create React App, Vite, etc.).
  • react-router-dom added to your dependencies.
  • One BrowserRouter at the app root.
  • Routes and Route used to declare pages.
  • Navigation built with NavLink for active styling.
  • A fallback Route (path="*") for 404 handling.

Practical implementation tips (developer-friendly)

  1. Keep pages as simple components: Home, About, Services, Contact. Put them in src/pages for clarity.
  2. Use a Layout component that includes your Navbar and Footer and renders child routes with an Outlet. This avoids repeating header/footer code.
  3. Use NavLink’s className or style-as-function to apply an active state, rather than doing manual path comparisons.
  4. For deep links under a section (e.g., /services/web-design), use nested routes so the parent layout remains consistent and the child content renders in-place.
  5. Avoid native anchor tags for internal links; they will cause full reloads and break the SPA experience.
  6. Add a simple 404 route as the last Route: when no path matches, render a helpful "Page not found" message.

Deployment pointers

Client-side routing needs one extra step on static hosts: configure the host to serve index.html for any route so deep links don’t 404.

  • Netlify: add a redirects rule to send all paths to index.html.
  • Vercel: it generally handles SPA rewrites automatically, but verify if you customize routing.

Also, set proper meta tags (React Helmet or similar) if SEO matters and consider server-side rendering later for improved SEO if your brochure site needs search visibility.

Best practices summary

  • Start small and centralize your route definitions.
  • Use semantic HTML for navigation and test keyboard accessibility.
  • Keep route paths lowercase and descriptive.
  • Plan for growth with nested routes and a layout component.

If you want a full walk-through and example code, there’s a longer guide and resources available. Check the original walkthrough at https://prateeksha.com/blog/react-router-basics-multi-page-navigation-brochure-website and browse related posts on https://prateeksha.com/blog. For agency help or custom builds, visit https://prateeksha.com.

Conclusion

React Router turns a simple React app into a well-structured brochure website with readable URLs, consistent layout, and fast navigation. Use a layout + outlet pattern, NavLink for active styling, and remember to configure your host for client-side routing on deployment. With these basics, your brochure site will be fast, maintainable, and ready to grow.

Top comments (0)