Route data is a set of named values supplied when generating a URL for an endpoint. Instead of hardcoding a link, give LinkGenerator an endpoint name and the values its route template needs. It combines them to produce a path, so a change to the template need not leave a hardcoded link broken. section 6.4 section 6.4.1
Listing 6.2 Generating a URL LinkGenerator and a named endpoint
app.MapGet("/product/{name}", (string name) => $"The product is {name}") #1
.WithName("product"); #2
app.MapGet("/links", (LinkGenerator links) => #3
{
string link = links.GetPathByName("product", #4
new { name = "big-widget"}); #4
return $"View the product at {link}"; #5
});
The named endpoint uses the template /product/{name}. GetPathByName supplies name through a C# anonymous object, producing /product/big-widget. section 6.4.1
The anonymous object can hold more than one value: each property supplies a named route value. When the selected template contains that parameter, the value goes into the generated path. Going the other direction, routing matches an incoming URL against a template and extracts route values that can be passed to an endpoint handler through model binding. section 6.4.1 section 6.3.1
Defaults and missing values
With a template containing {category}, {name=all}, and {id?}, /product/shoes gives category=shoes and name=all, but no id value. The longer /product/shoes/all gives the same category and name values. An optional parameter without a default belongs at the end of the template. section 6.3.2
Use GetPathByName for a path or GetUriByName for a complete URL. Endpoint names are case-sensitive and must be unique. If you supply a host when generating a complete URL, do not use an unvalidated host value. section 6.4.1

