Search code examples
javavaadinvaadin-flowvaadin14

Is it possible to have a navigation to another page in Vaadin if I using my mobile?


I want to make a special page in vaadin for mobile use only.

Assume that my current host page is localhost:8080. If I use my phone, then I will be navigated to m.localhost:8080 (or maybe localhost:8080/m) first.

Is that possible?

My mobile page is going to be a simplified page of my correct page.


Solution

  • If you want to use a separate host name for the mobile version, then it's probably best to do the redirect even before Vaadin is actively involved in any way. You can do this using e.g. a servlet filter that inspects all requests and chooses whether to do a redirect or to pass the request to the regular handler. For this purpose, you can look at the User-Agent header. The convention is that this header value will contain the string mobile somewhere for devices that want to be treated as mobile devices.

    Another alternative is to serve both variants from the same host name and using the same Vaadin application, but instead implement it so that e.g. your main layout component chooses to configure itself differently depending on the used device. For this purpose, you can also look at the user agent header (using VaadinRequest.getCurrent()).