Location class
Location
is a service that applications can use to interact with a
browser's URL.
Depending on which LocationStrategy is used, Location
will either
persist to the URL's path or the URL's hash segment.
Note: it's better to use Router#navigate
service to trigger route changes.
Use Location
only if you need to interact with or create normalized URLs
outside of routing.
Location
is responsible for normalizing the URL against the application's
base href. A normalized URL is absolute from the URL host, includes the
application's base href, and has no trailing slash:
/my/app/user/123
is normalizedmy/app/user/123
is not normalized/my/app/user/123/
is not normalized
Example
import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';
@Component(
// Should only be provided at the root.
providers: [routerProviders],
)
class AppComponent {
AppComponent(Location location) {
location.go('/foo');
}
}
- Annotations
-
- @Injectable()
Constructors
- Location(LocationStrategy locationStrategy)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- locationStrategy → LocationStrategy
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
back(
) → void - Navigates back in the platform's history.
-
forward(
) → void - Navigates forward in the platform's history.
-
go(
String path, [String query = '']) → void - Changes the browsers URL to the normalized version of the given URL, and pushes a new item onto the platform's history.
-
hash(
) → String -
Creates a combined hash code for a number of objects.
override
-
normalize(
String url) → String - Given a string representing a URL, returns the normalized URL path without leading or trailing slashes
-
normalizePath(
String path) → String -
Normalizes
path
for navigation. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
path(
) → String - Returns the normalized URL path.
-
prepareExternalUrl(
String url) → String -
Given a string representing a URL, returns the platform-specific external
URL path. If the given URL doesn't begin with a leading slash (
'/'
), this method adds one before normalizing. This method will also add a hash ifHashLocationStrategy
is used, or theappBaseHref
if thePathLocationStrategy
is in use. -
replaceState(
String path, [String query = '']) → void - Changes the browsers URL to the normalized version of the given URL, and replaces the top item on the platform's history stack.
-
subscribe(
void onNext(Object), [void onThrow(Object)?, void onReturn()?]) → Object -
Subscribe to the platform's
popState
events. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
joinWithSlash(
String start, String end) → String - Given 2 parts of a url, join them with a slash if needed.
-
normalizeQueryParams(
String params) → String - Given a string of url parameters, prepend with '?' if needed, otherwise return parameters as is.
-
stripTrailingSlash(
String url) → String - If url has a trailing slash, remove it, otherwise return url as is.