A static path segment, also called a literal segment, matches one fixed string in a URL path. In the pattern "capital/uk", the first segment must be "capital" and the second must be "uk", so only /capital/uk matches. section 13.1.5
Literal segments make routes more specific and help distinguish endpoints. They contrast with segment variables such as {country}, which match varying values and expose them through HttpRequest.RouteValues. section 13.1.5 section 27.1
Use literal segments when you need to:
- Give a route a recognizable, fixed URL prefix, such as controllers/{controller=Home}/{action=Index}/{id?}. section 27.1
- Separate otherwise similar endpoint patterns by adding specificity before considering route order or other routing configuration. section 13.3.2
A fixed route alongside variable routes
app.MapGet("capital/uk", new Capital().Invoke); app.MapGet("capital/{country}", Capital.Endpoint); The first mapping accepts only /capital/uk; the second accepts different country values and reads the matched value from RouteValues.
