use of com.vaadin.flow.router.Location in project flow by vaadin.
the class ViewRenderer method createEvent.
private LocationChangeEvent createEvent(NavigationEvent event, List<View> viewChain) {
String route = getRoute();
Map<String, String> routePlaceholders;
if (route != null) {
routePlaceholders = extractRoutePlaceholders(event.getLocation(), new RouteLocation(new Location(route)));
} else {
routePlaceholders = Collections.emptyMap();
}
return new LocationChangeEvent(event.getSource(), event.getUI(), event.getTrigger(), event.getLocation(), viewChain, routePlaceholders);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class UI method navigate.
/**
* Updates this UI to show the view corresponding to the given location and
* query parameters. The location must be a relative path without any ".."
* segments.
* <p>
* Besides the navigation to the {@code location} this method also updates
* the browser location (and page history).
*
* @see #navigate(String)
* @see RouterInterface#navigate(UI, Location, NavigationTrigger)
*
* @param location
* the location to navigate to, not {@code null}
* @param queryParameters
* query parameters that are used for navigation, not
* {@code null}
*/
public void navigate(String location, QueryParameters queryParameters) {
if (location == null) {
throw new IllegalArgumentException("Location may not be null");
}
if (queryParameters == null) {
throw new IllegalArgumentException("Query parameters may not be null");
}
if (!getRouterInterface().isPresent()) {
throw new IllegalStateException("Can't navigate when UI has no router");
}
Location navigationLocation = new Location(location, queryParameters);
if (!internals.hasLastHandledLocation() || !navigationLocation.getPathWithQueryParameters().equals(internals.getLastHandledLocation().getPathWithQueryParameters())) {
// Enable navigating back
getPage().getHistory().pushState(null, navigationLocation);
}
getRouterInterface().get().navigate(this, navigationLocation, NavigationTrigger.PROGRAMMATIC);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class NavigationStateRendererTest method instantiatorUse.
@Test
public void instantiatorUse() throws ServiceException {
MockVaadinServletService service = new MockVaadinServletService();
service.init(new MockInstantiator() {
@Override
public <T extends HasElement> T createRouteTarget(Class<T> routeTargetType, NavigationEvent event) {
Assert.assertEquals(Component.class, routeTargetType);
return (T) new Text("foo");
}
});
MockUI ui = new MockUI(new MockVaadinSession(service));
NavigationEvent event = new NavigationEvent(new Router(new TestRouteRegistry()), new Location(""), ui, NavigationTrigger.PAGE_LOAD);
NavigationStateRenderer renderer = new NavigationStateRenderer(navigationStateFromTarget(ChildConfiguration.class));
Component routeTarget = renderer.getRouteTarget(Component.class, event);
Assert.assertEquals(Text.class, routeTarget.getClass());
UI.setCurrent(null);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class LocationTest method parseLocation.
@Test
public void parseLocation() {
Location location = new Location("foo/bar/baz");
assertEquals(Arrays.asList("foo", "bar", "baz"), location.getSegments());
assertEquals("foo/bar/baz", location.getPath());
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class LocationTest method locationWithParametersPath_withoutTrailingSlash.
@Test
public void locationWithParametersPath_withoutTrailingSlash() {
String initialPath = "foo/bar";
QueryParameters queryParams = getQueryParameters();
Location location = new Location(initialPath, queryParams);
String pathWithParameters = location.getPathWithQueryParameters();
assertEquals(initialPath + '?' + queryParams.getQueryString(), pathWithParameters);
}
Aggregations