Package com.vaadin.flow.router
Class Location
- java.lang.Object
-
- com.vaadin.flow.router.Location
-
- All Implemented Interfaces:
Serializable
public class Location extends Object implements Serializable
Represents a relative URL made up of path segments and query parameters, but lacking e.g. the hostname that can also be present in URLs.For related utility methods, see
LocationUtil.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Location(String location)Creates a newLocationobject for given location string.Location(String location, QueryParameters queryParameters)Creates a newLocationobject for given location string and query parameters.Location(List<String> segments)Creates a new location based on a list of path segments.Location(List<String> segments, QueryParameters queryParameters)Creates a new location based on a list of path segments and query parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetFirstSegment()Gets the first segment of this path.StringgetPath()Gets the path of this location as a string.StringgetPathWithQueryParameters()Gets the path string withQueryParametersand including the possible fragment if one existed.QueryParametersgetQueryParameters()Gets the request parameters used for current location.List<String>getSegments()Gets all the path segments of this location.Optional<Location>getSubLocation()Creates a new location without the first path segment.LocationtoggleTrailingSlash()Removes or adds slash to the end of the location path.
-
-
-
Constructor Detail
-
Location
public Location(String location) throws InvalidLocationException
Creates a newLocationobject for given location string.This string can contain relative path and query parameters, if needed. A possible fragment
#fragmentis also retained.A possible "/" prefix of the location is ignored and a
nulllocation is interpreted as""- Parameters:
location- the relative location ornullwhich is interpreted as""]- Throws:
InvalidLocationException- If the given string cannot be used for theLocation
-
Location
public Location(String location, QueryParameters queryParameters) throws InvalidLocationException
Creates a newLocationobject for given location string and query parameters.The location string can not contain query parameters. To pass query parameters, either specify them in
QueryParametersin this constructor, or useLocation(String)A possible "/" prefix of the location is ignored and a
nulllocation is interpreted as""- Parameters:
location- the relative location ornullwhich is interpreted as""queryParameters- query parameters information, notnull- Throws:
InvalidLocationException- If the given string cannot be used for theLocation
-
Location
public Location(List<String> segments)
Creates a new location based on a list of path segments.- Parameters:
segments- a non-empty list of path segments, notnull
-
Location
public Location(List<String> segments, QueryParameters queryParameters)
Creates a new location based on a list of path segments and query parameters.- Parameters:
segments- a non-empty list of path segments, notnulland not emptyqueryParameters- query parameters information, notnull
-
-
Method Detail
-
getSegments
public List<String> getSegments()
Gets all the path segments of this location.- Returns:
- a list of path segments
-
getQueryParameters
public QueryParameters getQueryParameters()
Gets the request parameters used for current location.- Returns:
- the request parameters
-
getFirstSegment
public String getFirstSegment()
Gets the first segment of this path.- Returns:
- the first path segment, not
null
-
getSubLocation
public Optional<Location> getSubLocation()
Creates a new location without the first path segment. The result is empty if this location only consists of one segment.- Returns:
- an optional new location, or an empty optional if this location has only one path segment
-
getPath
public String getPath()
Gets the path of this location as a string.- Returns:
- the location string, not
null
-
getPathWithQueryParameters
public String getPathWithQueryParameters()
Gets the path string withQueryParametersand including the possible fragment if one existed.- Returns:
- path string with parameters
-
-