How can I use Hygraph as a backend for a React application with routing?
You can use Hygraph as a backend for your React application by creating a schema in Hygraph to store your content (e.g., cocktail details), then querying this data using GraphQL from your React frontend. The blog example demonstrates fetching cocktail data from Hygraph and displaying it in a React app with dynamic routing using React Router. For a full implementation, see the source code on GitHub. Note: The blog focuses on routing; for schema setup and data consumption, refer to the linked resources.
What are the steps to implement dynamic routing in React using data from Hygraph?
To implement dynamic routing in React with Hygraph data: 1) Create a schema in Hygraph for your content, 2) Fetch the data using GraphQL in your React app, 3) Use React Router's dynamic routes (e.g., /products/:slug), 4) Use the useParams hook to extract the slug and query Hygraph for the specific item. The blog provides code samples for each step. Note: Schema creation and GraphQL query details are not covered in the blog; refer to Hygraph documentation for those steps.
Does Hygraph support lazy loading and programmatic navigation in React apps?
Yes, Hygraph can be used as a backend for React apps that implement lazy loading and programmatic navigation. The blog demonstrates how to use React's lazy and Suspense for route-based code splitting, and how to use useNavigate for programmatic navigation. Hygraph's GraphQL API can be queried as needed within these components. Note: Hygraph does not provide frontend routing; it supplies the content for your React app to consume.
Features & Capabilities
What APIs does Hygraph provide for developers?
Hygraph offers several APIs: 1) GraphQL Content API for querying and manipulating content, 2) Management API for handling project structure, 3) Asset Upload API for uploading files, and 4) MCP Server API for secure communication with AI assistants. For details, see the API Reference documentation. Note: Some advanced features may require specific project configurations; see documentation for compatibility.
What integrations are available with Hygraph?
Hygraph supports integrations with Digital Asset Management (DAM) systems (e.g., Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), hosting platforms (Netlify, Vercel), Product Information Management (Akeneo), commerce solutions (BigCommerce), and translation/localization tools (EasyTranslate). For the full list, visit the Hygraph Marketplace. Note: Integration availability may depend on your plan and project setup.
What technical documentation is available for Hygraph?
Hygraph provides extensive technical documentation, including API references, schema guides, getting started tutorials, integration guides (e.g., Mux, Akeneo, Auth0), and AI feature documentation. Access all resources at hygraph.com/docs. Note: Documentation for Hygraph Classic is also available for legacy users.
What performance optimizations does Hygraph offer?
Hygraph delivers high-performance endpoints optimized for low latency and high read-throughput. A read-only cache endpoint provides 3-5x latency improvement for faster content delivery. Performance of the GraphQL API is actively measured, with practical optimization advice available in the GraphQL Report 2024. Note: Actual performance may vary based on project complexity and integration setup.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (as of August 3rd, 2022), ISO 27001 certified for hosting infrastructure, and GDPR compliant. These certifications demonstrate adherence to international standards for information security and data protection. For more details, see the Secure Features page. Note: Certification scope may vary by deployment region and project configuration.
What security features are included in Hygraph?
Hygraph includes granular permissions, SSO integrations (OIDC/LDAP/SAML), audit logs, encryption in transit and at rest, regular backups with one-click recovery, and secure API policies (custom origin policies, IP firewalls). All endpoints use SSL certificates. For more, see Hygraph's Secure Features. Note: Some features may require enterprise plans or specific configuration.
Implementation & Onboarding
How long does it take to implement Hygraph?
Implementation time varies by project complexity. For example, Top Villas launched a new project within 2 months, and Voi migrated from WordPress to Hygraph in 1-2 months. Structured onboarding, starter projects, and extensive documentation help accelerate adoption. See Getting Started for details. Note: Large-scale migrations or complex integrations may require additional time.
How easy is it to get started with Hygraph?
Hygraph offers a free signup, structured onboarding (introduction calls, account provisioning, technical kickoffs), starter projects, and comprehensive documentation. Community support is available via Slack, and training resources include webinars and live streams. See Hygraph Documentation for more. Note: Some onboarding resources may be tailored for enterprise customers.
Use Cases & Customer Success
Who can benefit from using Hygraph?
Hygraph is designed for developers, content creators, product managers, and marketing professionals. It is suitable for enterprises and high-growth companies in SaaS, eCommerce, media, healthcare, automotive, and more. See the case studies for industry examples. Note: Teams with highly specialized legacy requirements may need custom integration work.
What business impact can customers expect from using Hygraph?
Customers have achieved 3x faster time-to-market (Komax), 15% improved customer engagement (Samsung), and a 20% increase in website monetization (AutoWeb). Hygraph supports consistent content delivery, cost reduction, and scalability. See Hygraph case studies for more. Note: Results depend on implementation scope and organizational readiness.
What feedback have customers given about Hygraph's ease of use?
Customers praise Hygraph's intuitive interface, quick adaptability, and accessibility for non-technical users. For example, Sigurður G. (CTO) noted the UI is intuitive, and Anastasija S. (Product Content Coordinator) highlighted instant front-end updates. Charissa K. (Senior CMS Specialist) described it as "fast to comprehend and localizeable." Note: Some advanced features may require developer involvement for setup.
What industries are represented in Hygraph's customer base?
Hygraph's case studies include SaaS, marketplace, education technology, media and publication, healthcare, consumer goods, automotive, technology, fintech, travel and hospitality, food and beverage, eCommerce, agency, online gaming, events & conferences, government, consumer electronics, engineering, and construction. See case studies for details. Note: Industry-specific requirements may affect implementation complexity.
Can you share specific customer success stories with Hygraph?
Yes. Notable examples include Samsung (15% improved engagement), Komax (3x faster time-to-market), AutoWeb (20% increase in monetization), Voi (scaled multilingual content across 12 countries), and HolidayCheck (reduced developer bottlenecks). See Hygraph's case studies for more. Note: Outcomes vary by use case and implementation.
Pain Points & Limitations
What common pain points does Hygraph address?
Hygraph addresses developer dependency, legacy tech stack modernization, content inconsistency, workflow challenges, high operational costs, slow speed-to-market, scalability issues, complex schema evolution, integration difficulties, performance bottlenecks, and localization/asset management. Note: Detailed limitations not publicly documented; ask sales for specifics on edge cases or unsupported scenarios.
What are the limitations or scenarios where Hygraph may not be the best fit?
Detailed limitations are not publicly documented. For highly specialized legacy requirements, complex custom workflows, or unsupported integrations, consult Hygraph sales or technical support for specifics. Best fit for teams seeking a GraphQL-native, API-first CMS; teams needing deep legacy system integration may require additional customization.
Learn how to perform routing in React using React Router, as well as the various aspects of routing and how React Router handles them.
Last updated by Aagam
on Aug 07, 2026
Originally written by Joel
on Sep 06, 2022
React has no built-in router. Most React apps handle routing with React Router, now on v8, or with a framework like Next.js that comes with file-based routing. If you're building a client-side app and want full control over your routes, React Router is the standard choice; if you also need server rendering and data loading out of the box, start with a framework instead (see Next.js vs React).
React is an open-source frontend JavaScript library that allows developers to create websites and user interfaces using UI components and single-page applications. Routing is one of the most important features we always want to implement when developing these applications.
Routing redirects users to different pages based on their actions or requests. In React routing, you'll use an external library called React Router, which can be challenging to configure if you need help understanding how it works.
In this article, we will show you how to perform routing in React using React Router. Learn the various routing aspects and how React Router handles them, such as dynamic routing, programmatic navigation, no-matching routes, etc.
To fully comprehend and follow this guide, we would create an application that properly illustrates all aspects of navigation with appropriate use cases. We would create/use a cocktails app that retrieves data from Hygraph via GraphQL. This application, which can be accessed via this live link, uses all aspects of routing covered in this guide.
Editor's Note
Note: This guide only covers routing; however, the aspect of creating a schema on Hygraph and how we consumed the data will not be covered; notwithstanding, here is a link to the source code, and I have also included a picture of what the schema looks like in this article.
Prerequisite
You should have the following to follow along with this guide and code:
A fundamental understanding of HTML, CSS, and JavaScript
As previously stated, React makes use of an external library to handle routing; however, before we can implement routing with that library, we must first install it in our project, which is accomplished by running the following command in your terminal (within your project directory):
npm install react-router
After successfully installing the package, we can set up and configure React Router for our project.
If you've used React Router before, you may know the react-router-dom package. In v7 it became a thin re-export of react-router, and v8 removed it, so every import in this guide comes from react-router.
React Router modes in one minute
Since v7, React Router can be used in three ways, and you pick one per app:
Declarative mode is the classic setup: <BrowserRouter>, <Routes> and <Route> in JSX, plus Hooks like useNavigate and useParams. This guide uses declarative mode.
Data mode moves route configuration out of JSX into createBrowserRouter, which adds loaders, actions and pending states for data loading and form submissions.
Framework mode wraps React Router in a Vite plugin with file-based routes, server rendering, code splitting and type-safe route modules. It's the successor to Remix and the closest to a full framework like Next.js.
Start with declarative mode when you're adding routes to an existing client-side app. Move to data or framework mode when you want React Router to load data and render on the server for you.
How to setup React Router
To configure React Router, navigate to the main.jsx file, which is the root file, and import BrowserRouter from the react-router package that we installed, wrapping it around our App component as follows:
We have now successfully installed and imported React Router into our project; the next step is to use React Router to implement routing. The first step is configuring all of our routes (all the pages/components we want to navigate).
We would first create those components, in our case, three pages: the Home page, the About Page, and the Products Page. This GitHub repository contains the content for these pages. Once those pages are properly configured, we can now set up and configure our routes in the App.jsx file, which serves as the foundation for our React application:
// App.jsx
import{Routes,Route}from'react-router';
importHomefrom'./Pages/Home';
importAboutfrom'./Pages/About';
importProductsfrom'./Pages/Products';
constApp=()=>{
return(
<>
<Routes>
<Route path="/" element={<Home/>}/>
<Route path="/products" element={<Products/>}/>
<Route path="/about" element={<About/>}/>
</Routes>
</>
);
};
exportdefaultApp;
We can see in the above code that we imported Routes and Route components from react-router and then used them to declare the routes we want. All Routes are wrapped in the Routes tag, and these Routes have two major properties:
path: As the name implies, this identifies the path we want users to take to reach the set component. When we set the path to /about, for example, when the user adds /about to the URL link, it navigates to that page.
element: This contains the component that we want the set path to load. This is simple to understand, but remember to import any components we are using here, or else an error will occur.
Editor's Note
We created a folder (Pages) to keep all page components separate from actual components.
When we go to our browser and try to navigate via the URL, it will load whatever content we have on such pages.
Adding a navigation bar
Let us now create a standard Navigation bar component that can be used to navigate inside our application.
First, create the Navbar component.
// Components/NavBar.jsx
import{NavLink}from"react-router";
constNavBar=()=>{
return(
<nav>
<ul>
<li>
<NavLink to="/">Home</NavLink>
</li>
<li>
<NavLink to="/about">About</NavLink>
</li>
<li>
<NavLink to="/products">Products</NavLink>
</li>
</ul>
</nav>
);
};
exportdefaultNavBar;
The NavLink component from React Router is a special component that helps you navigate different routes using the to prop. The NavLink component also knows whether the route is currently "active" and adds a default active class to the link. We can use this class in our CSS to define some styling for active links, as shown below:
// index.css
ul li a {
color: #000;
}
ul li a:hover {
color: #00a8ff;
}
ul li a.active{
color: #00a8ff;
}
Also, we can assign our custom classes instead of using the default active class. The NavLink component gives us access to properties like isActive, which can be used like this.
...
<li>
<NavLink
to="/"
className={({ isActive })=>{
return isActive ?"active-link":"";
}}
>
Home
</NavLink>
</li>
...
Finally, let us use the Navbar component inside our App.
// App.jsx
importNavBarfrom"./Components/NavBar";
import{Routes,Route}from"react-router";
constApp=()=>{
return(
<>
<NavBar/>
<Routes>
...
</Routes>
</>
);
};
exportdefaultApp;
How to fix No Routes Found Error
When routing, a situation may cause a user to access an unconfigured route or a route that does not exist; when this occurs, React does not display anything on the screen except a warning with the message "No routes matched location."
This can be fixed by configuring a new route to return a specific component when a user navigates to an unconfigured route as follows:
// App.jsx
import{Routes,Route}from'react-router';
importNoMatchfrom'./Components/NoMatch';
constApp=()=>{
return(
<>
<Routes>
{/* ... */}
<Route path="*" element={<NoMatch/>}/>
</Routes>
</>
);
};
exportdefaultApp;
In the preceding code, we created a route with the path * to get all non-configured paths and assign them to the attached component.
Editor's Note
We created a component called NoMatch.jsx, but you can name yours whatever you want to display 404, page not found, on the screen, so users know they are on the wrong page. We can also add a button that takes the user to another page or back, which leads us to programmatic navigation.
Programmatic navigation is the process of navigating/redirecting a user as a result of an action on a route, such as a login or a signup action, order success, or when they click on a back button.
Let's first look at how we can redirect to a page when an action occurs, such as when a button is clicked. We accomplish this by adding an onClick event, but first, we must create the route in our App.jsx file. After that, we can import the useNavigate hook from react-router and use it to navigate programmatically as follows:
We already created a route with the path order-summary, so when this button is clicked, the user is automatically navigated to the orderSummary component attached to this route.
Ensure you already have the useNavigate hook imported and instantiated as we did earlier else this won’t work.
#How to implement dynamic routing with React Router
We created three files in our pages folder earlier to implement routing, one of which was the products component, which we will populate with Hygraph content. We created a schema in Hygraph to receive cocktail details, and this is how it looks:
We then filled it in with cocktail specifics. We will now use GraphQL to retrieve these data so that we can consume them in our React project. This is how the products page appears:
We fetched our content from Hygraph in the preceding code; if you already created your own schema, you can simply change the Endpoint URL and possibly the schema name if you gave it a different name.
Editor's Note
We added a button on each cocktail card so that a user can click it to view more details about each cocktail, but this would be done dynamically because we can create different components for each cocktail, which would be stressful if we had more than 5 different cocktails. Dynamic routing comes into play here.
We added a Link and used string interpolation to dynamically attach the slug of each product to the path, so we can get the slug and use it to get the data to show.
Let us now put dynamic routing into action.
The first step would be to create the component that we want to render dynamically, and for that we would create a ProductDetails.jsx file where we would dynamically fetch details of each product based on the slug passed through the URL, but for now we can just place dummy data into the component like this:
// ProductDetails.jsx
constProductDetails=()=>{
return(
<div className="container">
<h1>ProductsDetailsPage</h1>
</div>
);
};
exportdefaultProductDetails;
We can now proceed to create a route to handle dynamic routing in our App.jsx file this way:
We used slug, which can be anything, but this route will match any value and display the component as long as the pattern is the same, for example, http://localhost:5173/products/cocktail will show the ProductDetails component.
So far, we've dealt with the first part of dynamic routing. We must now obtain the parameter passed through the URL in order to dynamically query the data for the specific cocktail. This will be accomplished through the use of URL params.
How to use URL params to handle dynamic routing
We will import the useParams hook into the ProductDetails component so that we can use it to get the URL parameter and then use that parameter to query our data from Hygraph via GraphQL.
At this point, we have successfully been able to get the URL param passed. The getProductBySlug function lives in a small api.js file next to getAllCocktails and sends the GraphQL query to Hygraph:
We've already seen how to create routes and implement routing with React Router; now let's look at how to lazy load routes with React Router.
Lazy loading is a technique in which components that are not required on the home page are not loaded until a user navigates to that page, allowing our application to load faster than having to wait for the entire app to load at once. This contributes to improved performance, which leads to a positive user experience.
To implement lazy loading, simply go to App.jsx and wrap our routes with the Suspense component, along with a fallback props that are rendered on the screen until the component loads:
We wrapped the routes with the Suspense component, and it’s important for you to know that the fallback props can hold a component.
In data and framework mode, React Router can also lazy load route modules for you through the lazy route property, so you don't need to wrap routes in Suspense yourself.
#Where does the content behind your routes come from?
Every dynamic route in this app, like /products/:slug, is really a lookup: take the slug from the URL and ask a content API for the matching entry. That only stays simple when slugs, fields and content types are defined in a schema, so each route maps to one entry and nothing breaks when editors add the next cocktail. A schema like that also helps an AI coding agent generate the page or loader for a new route from your real model. Hygraph, the agentic content platform and headless CMS, gives you that model and a GraphQL API, and its MCP server lets Claude Code, Cursor or VS Code draft entries and read the schema without being able to delete or unpublish anything. When you're ready to grow the demo, read how to build your React app on a headless CMS.
We learned about routing and how to implement it in our React application in this guide. It is critical to understand that React Router is what allows us to perform single-page routing without reloading the application.
Build your React app on Hygraph
Model your content once and query it from every route with Hygraph's GraphQL API.
Mapping URLs to screens. React Router reads the current address, renders the component you assigned to that path and updates the URL when someone clicks a link or your code calls navigate. It also handles nested layouts, URL parameters like :slug and catch-all 404 routes in a single-page app.
Yes, and actively. React Router v8 shipped in June 2026 and requires React 19.2.7 or later. Remix merged into React Router with v7, so one team now maintains a router that covers simple client-side routes as well as framework features like server rendering and data loading.
Not for the basics. If you know React components and Hooks, you can set up BrowserRouter, a few Route elements and useNavigate in an afternoon. The learning curve shows up later, when you move to data or framework mode and add loaders, actions and server rendering.
React draws your UI, and React Router decides which part of it to show for the current URL. React itself has no concept of pages, so a routing library fills that gap in client-side apps. Frameworks like Next.js ship their own router, so you don't add React Router there.
Since v7, almost nothing. react-router-dom became a thin re-export of react-router, and v8 removed the package. For new projects, install react-router and import BrowserRouter, Routes, Link and the Hooks from it. Older code that imports from react-router-dom needs its imports updated before moving to v8.
Keep it in a structured content model with unique slugs. Each dynamic route then becomes one predictable query: read the slug with useParams and fetch the matching entry. A headless CMS like Hygraph gives you typed fields and a GraphQL API, so editors add new pages without anyone touching your route config.
Blog Authors
Aagam Vadecha
Joel Olawanle
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.
Learn how to perform routing in React using React Router, as well as the various aspects of routing and how React Router handles them.
Last updated by Aagam
on Aug 07, 2026
Originally written by Joel
on Sep 06, 2022
React has no built-in router. Most React apps handle routing with React Router, now on v8, or with a framework like Next.js that comes with file-based routing. If you're building a client-side app and want full control over your routes, React Router is the standard choice; if you also need server rendering and data loading out of the box, start with a framework instead (see Next.js vs React).
React is an open-source frontend JavaScript library that allows developers to create websites and user interfaces using UI components and single-page applications. Routing is one of the most important features we always want to implement when developing these applications.
Routing redirects users to different pages based on their actions or requests. In React routing, you'll use an external library called React Router, which can be challenging to configure if you need help understanding how it works.
In this article, we will show you how to perform routing in React using React Router. Learn the various routing aspects and how React Router handles them, such as dynamic routing, programmatic navigation, no-matching routes, etc.
To fully comprehend and follow this guide, we would create an application that properly illustrates all aspects of navigation with appropriate use cases. We would create/use a cocktails app that retrieves data from Hygraph via GraphQL. This application, which can be accessed via this live link, uses all aspects of routing covered in this guide.
Editor's Note
Note: This guide only covers routing; however, the aspect of creating a schema on Hygraph and how we consumed the data will not be covered; notwithstanding, here is a link to the source code, and I have also included a picture of what the schema looks like in this article.
Prerequisite
You should have the following to follow along with this guide and code:
A fundamental understanding of HTML, CSS, and JavaScript
As previously stated, React makes use of an external library to handle routing; however, before we can implement routing with that library, we must first install it in our project, which is accomplished by running the following command in your terminal (within your project directory):
npm install react-router
After successfully installing the package, we can set up and configure React Router for our project.
If you've used React Router before, you may know the react-router-dom package. In v7 it became a thin re-export of react-router, and v8 removed it, so every import in this guide comes from react-router.
React Router modes in one minute
Since v7, React Router can be used in three ways, and you pick one per app:
Declarative mode is the classic setup: <BrowserRouter>, <Routes> and <Route> in JSX, plus Hooks like useNavigate and useParams. This guide uses declarative mode.
Data mode moves route configuration out of JSX into createBrowserRouter, which adds loaders, actions and pending states for data loading and form submissions.
Framework mode wraps React Router in a Vite plugin with file-based routes, server rendering, code splitting and type-safe route modules. It's the successor to Remix and the closest to a full framework like Next.js.
Start with declarative mode when you're adding routes to an existing client-side app. Move to data or framework mode when you want React Router to load data and render on the server for you.
How to setup React Router
To configure React Router, navigate to the main.jsx file, which is the root file, and import BrowserRouter from the react-router package that we installed, wrapping it around our App component as follows:
We have now successfully installed and imported React Router into our project; the next step is to use React Router to implement routing. The first step is configuring all of our routes (all the pages/components we want to navigate).
We would first create those components, in our case, three pages: the Home page, the About Page, and the Products Page. This GitHub repository contains the content for these pages. Once those pages are properly configured, we can now set up and configure our routes in the App.jsx file, which serves as the foundation for our React application:
// App.jsx
import{Routes,Route}from'react-router';
importHomefrom'./Pages/Home';
importAboutfrom'./Pages/About';
importProductsfrom'./Pages/Products';
constApp=()=>{
return(
<>
<Routes>
<Route path="/" element={<Home/>}/>
<Route path="/products" element={<Products/>}/>
<Route path="/about" element={<About/>}/>
</Routes>
</>
);
};
exportdefaultApp;
We can see in the above code that we imported Routes and Route components from react-router and then used them to declare the routes we want. All Routes are wrapped in the Routes tag, and these Routes have two major properties:
path: As the name implies, this identifies the path we want users to take to reach the set component. When we set the path to /about, for example, when the user adds /about to the URL link, it navigates to that page.
element: This contains the component that we want the set path to load. This is simple to understand, but remember to import any components we are using here, or else an error will occur.
Editor's Note
We created a folder (Pages) to keep all page components separate from actual components.
When we go to our browser and try to navigate via the URL, it will load whatever content we have on such pages.
Adding a navigation bar
Let us now create a standard Navigation bar component that can be used to navigate inside our application.
First, create the Navbar component.
// Components/NavBar.jsx
import{NavLink}from"react-router";
constNavBar=()=>{
return(
<nav>
<ul>
<li>
<NavLink to="/">Home</NavLink>
</li>
<li>
<NavLink to="/about">About</NavLink>
</li>
<li>
<NavLink to="/products">Products</NavLink>
</li>
</ul>
</nav>
);
};
exportdefaultNavBar;
The NavLink component from React Router is a special component that helps you navigate different routes using the to prop. The NavLink component also knows whether the route is currently "active" and adds a default active class to the link. We can use this class in our CSS to define some styling for active links, as shown below:
// index.css
ul li a {
color: #000;
}
ul li a:hover {
color: #00a8ff;
}
ul li a.active{
color: #00a8ff;
}
Also, we can assign our custom classes instead of using the default active class. The NavLink component gives us access to properties like isActive, which can be used like this.
...
<li>
<NavLink
to="/"
className={({ isActive })=>{
return isActive ?"active-link":"";
}}
>
Home
</NavLink>
</li>
...
Finally, let us use the Navbar component inside our App.
// App.jsx
importNavBarfrom"./Components/NavBar";
import{Routes,Route}from"react-router";
constApp=()=>{
return(
<>
<NavBar/>
<Routes>
...
</Routes>
</>
);
};
exportdefaultApp;
How to fix No Routes Found Error
When routing, a situation may cause a user to access an unconfigured route or a route that does not exist; when this occurs, React does not display anything on the screen except a warning with the message "No routes matched location."
This can be fixed by configuring a new route to return a specific component when a user navigates to an unconfigured route as follows:
// App.jsx
import{Routes,Route}from'react-router';
importNoMatchfrom'./Components/NoMatch';
constApp=()=>{
return(
<>
<Routes>
{/* ... */}
<Route path="*" element={<NoMatch/>}/>
</Routes>
</>
);
};
exportdefaultApp;
In the preceding code, we created a route with the path * to get all non-configured paths and assign them to the attached component.
Editor's Note
We created a component called NoMatch.jsx, but you can name yours whatever you want to display 404, page not found, on the screen, so users know they are on the wrong page. We can also add a button that takes the user to another page or back, which leads us to programmatic navigation.
Programmatic navigation is the process of navigating/redirecting a user as a result of an action on a route, such as a login or a signup action, order success, or when they click on a back button.
Let's first look at how we can redirect to a page when an action occurs, such as when a button is clicked. We accomplish this by adding an onClick event, but first, we must create the route in our App.jsx file. After that, we can import the useNavigate hook from react-router and use it to navigate programmatically as follows:
We already created a route with the path order-summary, so when this button is clicked, the user is automatically navigated to the orderSummary component attached to this route.
Ensure you already have the useNavigate hook imported and instantiated as we did earlier else this won’t work.
#How to implement dynamic routing with React Router
We created three files in our pages folder earlier to implement routing, one of which was the products component, which we will populate with Hygraph content. We created a schema in Hygraph to receive cocktail details, and this is how it looks:
We then filled it in with cocktail specifics. We will now use GraphQL to retrieve these data so that we can consume them in our React project. This is how the products page appears:
We fetched our content from Hygraph in the preceding code; if you already created your own schema, you can simply change the Endpoint URL and possibly the schema name if you gave it a different name.
Editor's Note
We added a button on each cocktail card so that a user can click it to view more details about each cocktail, but this would be done dynamically because we can create different components for each cocktail, which would be stressful if we had more than 5 different cocktails. Dynamic routing comes into play here.
We added a Link and used string interpolation to dynamically attach the slug of each product to the path, so we can get the slug and use it to get the data to show.
Let us now put dynamic routing into action.
The first step would be to create the component that we want to render dynamically, and for that we would create a ProductDetails.jsx file where we would dynamically fetch details of each product based on the slug passed through the URL, but for now we can just place dummy data into the component like this:
// ProductDetails.jsx
constProductDetails=()=>{
return(
<div className="container">
<h1>ProductsDetailsPage</h1>
</div>
);
};
exportdefaultProductDetails;
We can now proceed to create a route to handle dynamic routing in our App.jsx file this way:
We used slug, which can be anything, but this route will match any value and display the component as long as the pattern is the same, for example, http://localhost:5173/products/cocktail will show the ProductDetails component.
So far, we've dealt with the first part of dynamic routing. We must now obtain the parameter passed through the URL in order to dynamically query the data for the specific cocktail. This will be accomplished through the use of URL params.
How to use URL params to handle dynamic routing
We will import the useParams hook into the ProductDetails component so that we can use it to get the URL parameter and then use that parameter to query our data from Hygraph via GraphQL.
At this point, we have successfully been able to get the URL param passed. The getProductBySlug function lives in a small api.js file next to getAllCocktails and sends the GraphQL query to Hygraph:
We've already seen how to create routes and implement routing with React Router; now let's look at how to lazy load routes with React Router.
Lazy loading is a technique in which components that are not required on the home page are not loaded until a user navigates to that page, allowing our application to load faster than having to wait for the entire app to load at once. This contributes to improved performance, which leads to a positive user experience.
To implement lazy loading, simply go to App.jsx and wrap our routes with the Suspense component, along with a fallback props that are rendered on the screen until the component loads:
We wrapped the routes with the Suspense component, and it’s important for you to know that the fallback props can hold a component.
In data and framework mode, React Router can also lazy load route modules for you through the lazy route property, so you don't need to wrap routes in Suspense yourself.
#Where does the content behind your routes come from?
Every dynamic route in this app, like /products/:slug, is really a lookup: take the slug from the URL and ask a content API for the matching entry. That only stays simple when slugs, fields and content types are defined in a schema, so each route maps to one entry and nothing breaks when editors add the next cocktail. A schema like that also helps an AI coding agent generate the page or loader for a new route from your real model. Hygraph, the agentic content platform and headless CMS, gives you that model and a GraphQL API, and its MCP server lets Claude Code, Cursor or VS Code draft entries and read the schema without being able to delete or unpublish anything. When you're ready to grow the demo, read how to build your React app on a headless CMS.
We learned about routing and how to implement it in our React application in this guide. It is critical to understand that React Router is what allows us to perform single-page routing without reloading the application.
Build your React app on Hygraph
Model your content once and query it from every route with Hygraph's GraphQL API.
Mapping URLs to screens. React Router reads the current address, renders the component you assigned to that path and updates the URL when someone clicks a link or your code calls navigate. It also handles nested layouts, URL parameters like :slug and catch-all 404 routes in a single-page app.
Yes, and actively. React Router v8 shipped in June 2026 and requires React 19.2.7 or later. Remix merged into React Router with v7, so one team now maintains a router that covers simple client-side routes as well as framework features like server rendering and data loading.
Not for the basics. If you know React components and Hooks, you can set up BrowserRouter, a few Route elements and useNavigate in an afternoon. The learning curve shows up later, when you move to data or framework mode and add loaders, actions and server rendering.
React draws your UI, and React Router decides which part of it to show for the current URL. React itself has no concept of pages, so a routing library fills that gap in client-side apps. Frameworks like Next.js ship their own router, so you don't add React Router there.
Since v7, almost nothing. react-router-dom became a thin re-export of react-router, and v8 removed the package. For new projects, install react-router and import BrowserRouter, Routes, Link and the Hooks from it. Older code that imports from react-router-dom needs its imports updated before moving to v8.
Keep it in a structured content model with unique slugs. Each dynamic route then becomes one predictable query: read the slug with useParams and fetch the matching entry. A headless CMS like Hygraph gives you typed fields and a GraphQL API, so editors add new pages without anyone touching your route config.
Blog Authors
Aagam Vadecha
Joel Olawanle
Share with others
Sign up for our newsletter!
Be the first to know about releases and industry news and insights.