Skip to content

Commit

Permalink
Update docs for Location type
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Mar 20, 2023
1 parent fe477f5 commit 5cca3e5
Showing 1 changed file with 77 additions and 13 deletions.
90 changes: 77 additions & 13 deletions packages/@ember/routing/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
You can pass an implementation name (`hash`, `history`, `none`) to force a
particular implementation to be used in your application.
See [HashLocation](/ember/release/classes/HashLocation).
See [HistoryLocation](/ember/release/classes/HistoryLocation).
See [NoneLocation](/ember/release/classes/NoneLocation).
- See [HashLocation](/ember/release/classes/HashLocation).
- See [HistoryLocation](/ember/release/classes/HistoryLocation).
- See [NoneLocation](/ember/release/classes/NoneLocation).
## Location API
Each location implementation must provide the following methods:
* implementation: returns the string name used to reference the implementation.
* 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.
* detect() (optional): instructs the location to do any feature detection
* `implementation`: returns the string name used to reference the implementation.
* `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.
* `detect()` (optional): instructs the location to do any feature detection
necessary. If the location needs to redirect to a different URL, it
can cancel routing by setting the `cancelRouterSetup` property on itself
to `false`.
Calling setURL or replaceURL will not trigger onUpdateURL callbacks.
Calling `setURL` or `replaceURL` will not trigger onUpdateURL callbacks.
## Custom implementation
Expand Down Expand Up @@ -59,18 +59,82 @@
}
```
@for @ember/routing/location
@class Location
@private
@since 5.0.0
@public
*/
export interface Location {
implementation: string;
/**
* Returns the string name used to reference the implementation.
*
* @property implementation
* @type String
* @public
*/
implementation: keyof Registry & string;

/**
* If the location needs to redirect to a different URL, it can cancel routing
* by setting the `cancelRouterSetup` property on itself to false.
* @property cancelRouterSetup
* @type Boolean
* @optional
* @default true
* @public
*/
cancelRouterSetup?: boolean;

/**
* The current URL.
* @property
* @type String
* @public
*/
getURL(): string;

/**
* Sets the current URL. Calling `setURL` will not trigger `onUpdateURL`
* callbacks.
*
* @public
* @method
* @param {String} url the new URL to update to.
*/
setURL(url: string): void;

/**
* Replace the current URL (optional). Calling `replaceURL` will not trigger
* `onUpdateURL` callbacks.
*
* @public
* @method
* @param {String} url the new URL to replace the current URL with.
*/
replaceURL?(url: string): void;

/**
* triggers the callback when the URL changes.
* @param {(newUrl: string) => void} callback A function to run when the URL
* changes. The the new URL string is provided as the only argument.
*/
onUpdateURL(callback: UpdateCallback): void;

/**
* Formats url to be placed into href attribute.
*
* @public
* @method
* @param {String} url the url to format
*/
formatURL(url: string): string;
/**
* Instructs the location to do any feature detection necessary. If the
* location needs to redirect to a different URL, it can cancel routing by
* setting the cancelRouterSetup property on itself to false.
*/
detect?(): void;

initState?(): void;
destroy(): void;
}
Expand Down

0 comments on commit 5cca3e5

Please sign in to comment.