From 3f19343c7d9ce75569b952758bd236af94956061 Mon Sep 17 00:00:00 2001 From: Matthew Riley Date: Fri, 22 Sep 2017 13:54:14 -0700 Subject: [PATCH] [docs] Document evaluation order for routes (#297) --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8dcd718..b096bf6 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,14 @@ r.HandleFunc("/products", ProductsHandler). Schemes("http") ``` +Routes are tested in the order they were added to the router. If two routes match, the first one wins: + +```go +r := mux.NewRouter() +r.HandleFunc("/specific", specificHandler) +r.PathPrefix("/").Handler(catchAllHandler) +``` + Setting the same matching conditions again and again can be boring, so we have a way to group several routes that share the same requirements. We call it "subrouting". For example, let's say we have several URLs that should only match when the host is `www.example.com`. Create a route for that host and get a "subrouter" from it: