Skip to content
BENIBIX Learn

Web Routing

Development🌐 Web DevelopmentFrameworks

Also known as Routing, Route

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

Think of it like

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

Example

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

Why it matters

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

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 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.

Common mistake

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

Key takeaways

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