Class Location

public

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.

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): formats url to be placed into href attribute.

Calling setURL or replaceURL will not trigger onUpdateURL callbacks.

Custom implementation

Ember scans app/locations/* for extending the Location API.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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);
  }
}

Show:

Methods

Properties

Events

No documented items