Route Parameters
Route parameters are dynamic segments in a URL that allow extra information to be passed to a view. They are appended to the route path and can be used to personalize responses or modify application behavior.
For example, if an application has a greet route that accepts a string parameter, users can call it with URLs like:
-
/greet/John -
/greet/Jane -
/greet/World
Here, "John", "Jane", and "World" are parameter values that the greet route can use to generate a response.
Route Parameters vs Static Routes
Static routes always take precedence over dynamic ones. For instance, consider an application with both a customer route (which accepts a string parameter), and a customer/list route:
-
/customer/cu1234→ Calls thecustomerroute with"cu1234"as the parameter value. -
/customer/details→ Calls thecustomerroute with"details"as the parameter value. -
/customer/list→ Calls the dedicatedcustomer/listroute. -
/customer→ Returns a404 Not Founderror, unless the parameter is explicitly declared optional.