Work in progress

Defining Routes With @Route

The @Route annotation allows you to define an arbitrary component as a route target for a given URL fragment. For example:

Java

  1. @Route("")
  2. public class HelloWorld extends Div {
  3. public HelloWorld() {
  4. setText("Hello world");
  5. }
  6. }

This defines the HelloWorld component as the default route target for the application (empty route). You can define a separate component for a different route like this:

Java

  1. @Route("some/path")
  2. public class SomePathComponent extends Div {
  3. public SomePathComponent() {
  4. setText("Hello @Route!");
  5. }
  6. }
  • Assuming your app is running from the root context, when the user navigates to http://example.com/some/path, either by clicking a link in the application or entering the address in the address bar, the SomePathComponent component is shown on the page.
Tip
If you leave out the parameter to a Route annotation, the route target will be derived from the class name. For example MyEditor will become “myeditor”, PersonView will become “person” and MainView will become “”.

For nested route definitions see: ParentLayout route control using @RoutePrefix