com.vaadin.flow.router.
Class Location
- java.lang.Object
-
- com.vaadin.flow.router.Location
-
All Implemented Interfaces:
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.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description 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.
Location(String location)
Creates a new
Location
object for given location string.Location(String location, QueryParameters queryParameters)
Creates a new
Location
object for given location string and query parameters.
-
Method Summary
All Methods Modifier and Type Method and Description String
getFirstSegment()
Gets the first segment of this path.
String
getPath()
Gets the path of this location as a string.
String
getPathWithQueryParameters()
Gets the path string with
QueryParameters
.QueryParameters
getQueryParameters()
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.
Location
toggleTrailingSlash()
Removes or adds slash to the end of the location path.
-
-
-
Constructor Detail
-
Location
public Location(String location)
Creates a new
Location
object for given location string. This string can contain relative path and query parameters, if needed.Parameters:
location
- the relative location, notnull
-
Location
public Location(String location, QueryParameters queryParameters)
Creates a new
Location
object for given location string and query parameters. Location string can not contain query parameters or exception will be thrown. To pass query parameters, either specify them inQueryParameters
in this constructor, or useLocation(String)
Parameters:
location
- the relative location, notnull
queryParameters
- query parameters information, notnull
Throws:
IllegalArgumentException
- if location string contains query parameters inside
-
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, notnull
and 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 with
QueryParameters
.Returns:
path string with parameters
-
-