Class Location
publicimport Location from '@ember/routing/location';
Location
defines an interface to be implemented by location
APIs. It is
not user-constructible; the only valid way to get a Location
is via one of
its concrete implementations.
Implementations
You can pass an implementation name (hash
, history
, none
) to force a
particular implementation to be used in your application.
- See HashLocation.
- See HistoryLocation.
- See NoneLocation.
Location API
Each location implementation must provide the following methods:
getURL
: returns the current URL.setURL(path)
: sets the current URL.replaceURL(path)
: replace the current URL (optional).onUpdateURL(callback)
: triggers the callback when the URL changes.formatURL(url)
: formatsurl
to be placed intohref
attribute.
Calling setURL
or replaceURL
will not trigger onUpdateURL callbacks.
Custom implementation
Ember scans app/locations/*
for extending the Location API.
Example:
import HistoryLocation from '@ember/routing/history-location';
export default class MyHistory {
implementation = 'my-custom-history';
constructor() {
this._history = HistoryLocation.create(...arguments);
}
create() {
return new this(...arguments);
}
pushState(path) {
this._history.pushState(path);
}
}
formatURL (url) public
Defined in packages/@ember/routing/location.ts:109
- url
- String
the url to format
Formats url to be placed into href attribute.
replaceURL (url) public
Defined in packages/@ember/routing/location.ts:92
- url
- String
the new URL to replace the current URL with.
Replace the current URL (optional). Calling replaceURL
will not trigger
onUpdateURL
callbacks.
setURL (url) public
Defined in packages/@ember/routing/location.ts:82
- url
- String
the new URL to update to.
Sets the current URL. Calling setURL
will not trigger onUpdateURL
callbacks.