URL Parameter Mapping: # URL Parameter Mapping for Vaadin Flow
While Router: add support for routes like `/orders/:id/edit` where the parameter is in the middle · Issue #2740 · vaadin/flow · GitHub and
Router: Multiple optional parameters support · Issue #4213 · vaadin/flow · GitHub are still in the works,
the need for flexible parametrized routes still exist. This
helper implementation lives on top of built in HasUrlParameter
and provides support for named parameters.
Simple usage example:
import org.vaadin.flow.helper.*;
...
@Route("example")
@UrlParameterMapping(":exampleId/:orderId")
// Will match /example/12345/ORD223434, set exampleId = 12345 and
// call setOrder("ORD223434")
// Otherwise user will be rerouted to default NotFoundException view
class MyView extends Div implements HasUrlParameterMapping {
// Note: parameter fields/setters should be public
@UrlParameter
public Integer exampleId;
@UrlParameter(name = "orderId", regEx = "ORD[0-9]{6}")
public setOrder(String order) { ... }
...
}
The following features are implemented:
- Support for
Integer
,Long
,Boolean
,String
andUUID
properties (with automatic regular expression checks) - Parameter placeholders:
order/:orderId
- Optional parameters:
order/:orderId[/:rowId]
- Parameters in the middle of path:
order/:orderId/edit
- Multiple alternative mappings
- (Optional) Automatic rerouting to view.
- Inline regular expressions:
forum/thread/:threadId/.*
- Custom regular expressions:
@UrlParameter(regEx = "overview|samples|links")
- Dynamic regular expressions for parameters
RequestHandler
support- URL formatting
- Query parameters support