Package com.vaadin.browserless.internal
Class Routes
java.lang.Object
com.vaadin.browserless.internal.Routes
- All Implemented Interfaces:
Serializable
A configuration object of all routes and error routes in the application.
Simply use
autoDiscoverViews(String...) to discover everything.
To speed up the tests, you can create one instance of this class only, then
reuse that instance in every call to MockVaadin.setup(com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, java.util.Set<? extends java.lang.Class<?>>, com.vaadin.browserless.BrowserlessConfiguration).
routes: a list of all route views in your application. Vaadin will ignore any routes not present here.errorRoutes: a list of all error views in your application. Vaadin will ignore any error views not present here.layouts: a list of allLayout-annotatedRouterLayoutclasses. These are automatically applied to routes that do not explicitly specify a layout in theirRouteannotation.skipPwaInit: if true, the PWA initialization code is skipped in Vaadin, which dramatically speeds up theMockVaadin.setup(com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, java.util.Set<? extends java.lang.Class<?>>, com.vaadin.browserless.BrowserlessConfiguration)from 2 seconds to 50ms. Since that's usually what you want to do, this defaults to true.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRoutes()Creates an empty configuration, with onlyMockRouteNotFoundErrorregistered as an error route, and with the PWA initialization skipped.Routes(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit) Creates the configuration. -
Method Summary
Modifier and TypeMethodDescriptionAuto-discovers everything in the whole classpath, registers it intothisand returnsthis.autoDiscoverViews(String... packageNames) Auto-discovers everything, registers it intothisand returnsthis.static voidclearPwaClass(com.vaadin.flow.server.startup.ApplicationRouteRegistry registry) Clears the PWA class config from the given registry.copy(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit) Creates a new configuration with the given values; the sets are not copied.booleanReturns all error views in the application.Returns allLayout-annotatedRouterLayoutclasses.Returns all route views in the application.booleanWhether the PWA initialization code is skipped in Vaadin.inthashCode()Creates a new configuration containing the routes, error routes and layouts of both this and the other configuration.voidregister(com.vaadin.flow.server.VaadinContext sc) Registers all routes to the Vaadin registry.voidsetSkipPwaInit(boolean skipPwaInit) Sets whether the PWA initialization code is skipped in Vaadin.toString()
-
Constructor Details
-
Routes
public Routes(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit) Creates the configuration.- Parameters:
routes- the route views, mutable.errorRoutes- the error views, mutable.layouts- theLayout-annotated router layouts, mutable.skipPwaInit- whether to skip the PWA initialization.
-
Routes
public Routes()Creates an empty configuration, with onlyMockRouteNotFoundErrorregistered as an error route, and with the PWA initialization skipped.
-
-
Method Details
-
getRoutes
Returns all route views in the application.- Returns:
- the mutable set of route views.
-
getErrorRoutes
Returns all error views in the application.- Returns:
- the mutable set of error views.
-
getLayouts
Returns allLayout-annotatedRouterLayoutclasses.- Returns:
- the mutable set of layouts.
-
getSkipPwaInit
public boolean getSkipPwaInit()Whether the PWA initialization code is skipped in Vaadin.- Returns:
- true if the PWA initialization is skipped.
-
setSkipPwaInit
public void setSkipPwaInit(boolean skipPwaInit) Sets whether the PWA initialization code is skipped in Vaadin.- Parameters:
skipPwaInit- true to skip the PWA initialization.
-
register
public void register(com.vaadin.flow.server.VaadinContext sc) Registers all routes to the Vaadin registry. Automatically called fromMockVaadin.setup(com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, java.util.Set<? extends java.lang.Class<?>>, com.vaadin.browserless.BrowserlessConfiguration).- Parameters:
sc- the Vaadin context.
-
autoDiscoverViews
Auto-discovers everything in the whole classpath, registers it intothisand returnsthis. This is quite slow; considerautoDiscoverViews(String...)with package names instead.- Returns:
- this
-
autoDiscoverViews
Auto-discovers everything, registers it intothisand returnsthis.Route-annotated views go intoroutesHasErrorParametererror views go intoerrorRoutes
- Parameters:
packageNames- set the package name for the detector to be faster; or provide null to scan the whole classpath, but this is quite slow.- Returns:
- this
-
merge
Creates a new configuration containing the routes, error routes and layouts of both this and the other configuration.- Parameters:
other- the other configuration.- Returns:
- a new merged configuration; uses this configuration's
skipPwaInit.
-
toString
-
copy
public Routes copy(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit) Creates a new configuration with the given values; the sets are not copied.- Parameters:
routes- the route views.errorRoutes- the error views.layouts- the router layouts.skipPwaInit- whether to skip the PWA initialization.- Returns:
- the new configuration.
-
hashCode
public int hashCode() -
equals
-
clearPwaClass
public static void clearPwaClass(com.vaadin.flow.server.startup.ApplicationRouteRegistry registry) Clears the PWA class config from the given registry.- Parameters:
registry- the registry.
-