|
36 | 36 | import com.vaadin.flow.dom.Element;
|
37 | 37 | import com.vaadin.flow.internal.JsonSerializer;
|
38 | 38 | import com.vaadin.flow.internal.UrlUtil;
|
| 39 | +import com.vaadin.flow.router.HasUrlParameter; |
39 | 40 | import com.vaadin.flow.router.QueryParameters;
|
40 | 41 | import com.vaadin.flow.router.RouteAlias;
|
41 | 42 | import com.vaadin.flow.router.RouteConfiguration;
|
42 | 43 | import com.vaadin.flow.router.RouteParameters;
|
43 | 44 | import com.vaadin.flow.router.internal.ConfigureRoutes;
|
| 45 | +import com.vaadin.flow.router.internal.HasUrlParameterFormat; |
44 | 46 |
|
45 | 47 | import elemental.json.JsonArray;
|
46 | 48 |
|
@@ -103,6 +105,26 @@ public SideNavItem(String label, Class<? extends Component> view) {
|
103 | 105 | setLabel(label);
|
104 | 106 | }
|
105 | 107 |
|
| 108 | + /** |
| 109 | + * Creates a new menu item using the given label that links to the given |
| 110 | + * view, which must implement {@link HasUrlParameter}. |
| 111 | + * |
| 112 | + * @param label |
| 113 | + * the label for the item |
| 114 | + * @param view |
| 115 | + * the view to link to, must implement {@link HasUrlParameter} |
| 116 | + * @param parameter |
| 117 | + * the URL parameter for the view |
| 118 | + * @param <T> |
| 119 | + * the type of the URL parameter |
| 120 | + * @param <C> |
| 121 | + * the type of the view |
| 122 | + */ |
| 123 | + public <T, C extends Component & HasUrlParameter<T>> SideNavItem( |
| 124 | + String label, Class<? extends C> view, T parameter) { |
| 125 | + this(label, view, HasUrlParameterFormat.getParameters(parameter)); |
| 126 | + } |
| 127 | + |
106 | 128 | /**
|
107 | 129 | * Creates a new menu item using the given label that links to the given
|
108 | 130 | * view.
|
@@ -262,6 +284,33 @@ public void setPath(Class<? extends Component> view) {
|
262 | 284 | setPath(view, RouteParameters.empty());
|
263 | 285 | }
|
264 | 286 |
|
| 287 | + /** |
| 288 | + * Retrieves {@link com.vaadin.flow.router.Route} and |
| 289 | + * {@link com.vaadin.flow.router.RouteAlias} annotations from the specified |
| 290 | + * view, and then sets the corresponding path and path aliases for this |
| 291 | + * item. |
| 292 | + * <p> |
| 293 | + * Note: Vaadin Router will be used to determine the URL path of the view |
| 294 | + * and this URL will be then set to this navigation item using |
| 295 | + * {@link SideNavItem#setPath(String)}. |
| 296 | + * |
| 297 | + * @param view |
| 298 | + * The view to link to. The view should be annotated with the |
| 299 | + * {@link com.vaadin.flow.router.Route} annotation and must |
| 300 | + * implement {@link HasUrlParameter}. Set to null to disable |
| 301 | + * navigation for this item. |
| 302 | + * @param parameter |
| 303 | + * the URL parameter for the view |
| 304 | + * @param <T> |
| 305 | + * the type of the URL parameter |
| 306 | + * @param <C> |
| 307 | + * the type of the view |
| 308 | + */ |
| 309 | + public <T, C extends Component & HasUrlParameter<T>> void setPath( |
| 310 | + Class<? extends C> view, T parameter) { |
| 311 | + setPath(view, HasUrlParameterFormat.getParameters(parameter)); |
| 312 | + } |
| 313 | + |
265 | 314 | /**
|
266 | 315 | * Retrieves {@link com.vaadin.flow.router.Route} and
|
267 | 316 | * {@link com.vaadin.flow.router.RouteAlias} annotations from the specified
|
|
0 commit comments