# Web Routing

> Matching each web address to the page or code that handles it.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Routing, Route

## Think of it like

Think of it like a post room. Each letter goes to the right desk based on the name on it.

## Definition

Routing is how a web app decides what to show or run for each web address. A route links a path, like /menu or /orders/42, to the code that handles it. On the server, routing picks which function answers a request. In a single-page app, a router swaps the page in the browser without a reload. Parts of the path, like the 42, can be read as inputs.

## Example

Jack's shop has a route for /orders/:id. When Emma visits /orders/42, the code loads order 42.

## Example code

```javascript
app.get("/orders/:id", (req, res) => {
  res.send(`Order ${req.params.id}`);
});
```

Any address like /orders/42 runs this code, with 42 as the id.

## Why it matters

Routes are the map of your app. Clear routes make clear web addresses.

## Common mistake

Putting a broad route before a narrow one. The broad one catches the request first, so the narrow one never runs.

## Three principles

- **Path to code.** Each address has a handler.
- **Server or browser.** Both can route.
- **Paths carry inputs.** Like the id in /orders/42.

## Related terms

- [Single-Page Application (SPA)](https://learn.benibix.com/term/development/single-page-application)
- [Back End](https://learn.benibix.com/term/development/back-end)
- [Express.js](https://learn.benibix.com/term/development/express)
- [Next.js](https://learn.benibix.com/term/development/nextjs)
- [Middleware](https://learn.benibix.com/term/development/middleware)

---

Source: https://learn.benibix.com/term/development/routing
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
