Browse Source

[docs] Document evaluation order for routes (#297)

pull/301/head
Matthew Riley 8 years ago committed by Matt Silverlock
parent
commit
3f19343c7d
  1. 8
      README.md

8
README.md

@ -135,6 +135,14 @@ r.HandleFunc("/products", ProductsHandler). @@ -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:

Loading…
Cancel
Save