docs(API): 翻译完了 Location

This commit is contained in:
Zhicheng Wang 2018-09-04 09:19:39 +08:00
parent eb075b665f
commit 391aed864a
2 changed files with 47 additions and 1 deletions

View File

@ -44,7 +44,7 @@
[x] | common/AsyncPipe | 0.45
[x] | core/ViewContainerRef | 0.42
[x] | common/NgTemplateOutlet | 0.42
[ ] | common/Location | 0.41
[x] | common/Location | 0.41
[ ] | platform-browser/BrowserModule | 0.40
[ ] | common/DecimalPipe | 0.40
[ ] | common/CurrencyPipe | 0.39

View File

@ -24,20 +24,38 @@ export interface PopStateEvent {
*
* A service that applications can use to interact with a browser's URL.
*
* URL
*
* Depending on which {@link LocationStrategy} is used, `Location` will either persist
* to the URL's path or the URL's hash segment.
*
* 使 {@link LocationStrategy}`Location` 使 URL 使 URL `#`
*
* Note: it's better to use {@link Router#navigate} service to trigger route changes. Use
* `Location` only if you need to interact with or create normalized URLs outside of
* routing.
*
* 使 {@link Router#navigate} URL `Location`
*
* `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:
*
* `Location` base href URL
* URL host
*
* - `/my/app/user/123` is normalized
*
* `/my/app/user/123`
*
* - `my/app/user/123` **is not** normalized
*
* `my/app/user/123`
*
* - `/my/app/user/123/` **is not** normalized
*
* `/my/app/user/123/`
*
* ### Example
* {@example common/location/ts/path_location_component.ts region='LocationComponent'}
*
@ -67,6 +85,8 @@ export class Location {
/**
* Returns the normalized URL path.
*
* URL
*/
// TODO: vsavkin. Remove the boolean flag and always include hash once the deprecated router is
// removed.
@ -76,6 +96,8 @@ export class Location {
/**
* Normalizes the given path and compares to the current normalized path.
*
*
*/
isCurrentPathEqualTo(path: string, query: string = ''): boolean {
return this.path() == this.normalize(path + Location.normalizeQueryParams(query));
@ -84,6 +106,8 @@ export class Location {
/**
* Given a string representing a URL, returns the normalized URL path without leading or
* trailing slashes.
*
* URL URL
*/
normalize(url: string): string {
return Location.stripTrailingSlash(_stripBaseHref(this._baseHref, _stripIndexHtml(url)));
@ -94,6 +118,11 @@ export class Location {
* If the given URL doesn't begin with a leading slash (`'/'`), this method adds one
* before normalizing. This method will also add a hash if `HashLocationStrategy` is
* used, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
*
* URL URL
* URL 使`'/'`
* 使 `HashLocationStrategy` `#` 使 `PathLocationStrategy` `APP_BASE_HREF`
*
*/
prepareExternalUrl(url: string): string {
if (url && url[0] !== '/') {
@ -106,6 +135,8 @@ export class Location {
/**
* Changes the browsers URL to the normalized version of the given URL, and pushes a
* new item onto the platform's history.
*
* URL URL
*/
go(path: string, query: string = '', state: any = null): void {
this._platformStrategy.pushState(state, '', path, query);
@ -114,6 +145,8 @@ export class Location {
/**
* Changes the browsers URL to the normalized version of the given URL, and replaces
* the top item on the platform's history stack.
*
* URL URL
*/
replaceState(path: string, query: string = '', state: any = null): void {
this._platformStrategy.replaceState(state, '', path, query);
@ -121,16 +154,22 @@ export class Location {
/**
* Navigates forward in the platform's history.
*
*
*/
forward(): void { this._platformStrategy.forward(); }
/**
* Navigates back in the platform's history.
*
* 退
*/
back(): void { this._platformStrategy.back(); }
/**
* Subscribe to the platform's `popState` events.
*
* `popState`
*/
subscribe(
onNext: (value: PopStateEvent) => void, onThrow?: ((exception: any) => void)|null,
@ -141,6 +180,8 @@ export class Location {
/**
* Given a string of url parameters, prepend with '?' if needed, otherwise return parameters as
* is.
*
* URL '?'
*/
public static normalizeQueryParams(params: string): string {
return params && params[0] !== '?' ? '?' + params : params;
@ -148,6 +189,8 @@ export class Location {
/**
* Given 2 parts of a url, join them with a slash if needed.
*
* url join
*/
public static joinWithSlash(start: string, end: string): string {
if (start.length == 0) {
@ -176,6 +219,9 @@ export class Location {
* If url has a trailing slash, remove it, otherwise return url as is. This
* method looks for the first occurrence of either #, ?, or the end of the
* line as `/` characters after any of these should not be replaced.
*
* url
* `#``?` `/` url `#``?`
*/
public static stripTrailingSlash(url: string): string {
const match = url.match(/#|\?|$/);