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.
For related utility methods, see
LocationUtil
.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor Description 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.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 Modifier and Type Method 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
and including the possible fragment if one existed.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) throws InvalidLocationException
Creates a new
Location
object for given location string.This string can contain relative path and query parameters, if needed. A possible fragment
#fragment
is also retained.A possible "/" prefix of the location is ignored and a
null
location is interpreted as""
Parameters:
location
- the relative location ornull
which 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 new
Location
object for given location string and query parameters.The location string can not contain query parameters. To pass query parameters, either specify them in
QueryParameters
in this constructor, or useLocation(String)
A possible "/" prefix of the location is ignored and a
null
location is interpreted as""
Parameters:
location
- the relative location ornull
which is interpreted as""
queryParameters
- query parameters information, notnull
Throws:
IllegalArgumentException
- if location string contains query parameters insideInvalidLocationException
- 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, 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
and including the possible fragment if one existed.Returns:
path string with parameters
-
-