refactor(router): code cleanup
This commit is contained in:
parent
349ad75de3
commit
307c4693dc
|
@ -96,7 +96,7 @@ export class Location {
|
|||
* used, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
|
||||
*/
|
||||
prepareExternalUrl(url: string): string {
|
||||
if (url.length > 0 && !url.startsWith('/')) {
|
||||
if (url && url[0] !== '/') {
|
||||
url = '/' + url;
|
||||
}
|
||||
return this._platformStrategy.prepareExternalUrl(url);
|
||||
|
@ -143,7 +143,7 @@ export class Location {
|
|||
* is.
|
||||
*/
|
||||
public static normalizeQueryParams(params: string): string {
|
||||
return (params.length > 0 && params.substring(0, 1) != '?') ? ('?' + params) : params;
|
||||
return params && params[0] !== '?' ? '?' + params : params;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,25 +175,13 @@ export class Location {
|
|||
/**
|
||||
* If url has a trailing slash, remove it, otherwise return url as is.
|
||||
*/
|
||||
public static stripTrailingSlash(url: string): string {
|
||||
if (/\/$/g.test(url)) {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
public static stripTrailingSlash(url: string): string { return url.replace(/\/$/, ''); }
|
||||
}
|
||||
|
||||
function _stripBaseHref(baseHref: string, url: string): string {
|
||||
if (baseHref.length > 0 && url.startsWith(baseHref)) {
|
||||
return url.substring(baseHref.length);
|
||||
}
|
||||
return url;
|
||||
return baseHref && url.startsWith(baseHref) ? url.substring(baseHref.length) : url;
|
||||
}
|
||||
|
||||
function _stripIndexHtml(url: string): string {
|
||||
if (/\/index.html$/g.test(url)) {
|
||||
// '/index.html'.length == 11
|
||||
return url.substring(0, url.length - 11);
|
||||
}
|
||||
return url;
|
||||
return url.replace(/\/index.html$/, '');
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import {mergeMap} from 'rxjs/operator/mergeMap';
|
|||
import {reduce} from 'rxjs/operator/reduce';
|
||||
|
||||
import {applyRedirects} from './apply_redirects';
|
||||
import {Data, ResolveData, Routes, validateConfig} from './config';
|
||||
import {ResolveData, Routes, validateConfig} from './config';
|
||||
import {createRouterState} from './create_router_state';
|
||||
import {createUrlTree} from './create_url_tree';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
|
@ -38,7 +38,7 @@ import {UrlSerializer, UrlTree, containsTree, createEmptyUrlTree} from './url_tr
|
|||
import {andObservables, forEach, merge, waitForMap, wrapIntoObservable} from './utils/collection';
|
||||
import {TreeNode} from './utils/tree';
|
||||
|
||||
declare var Zone: any;
|
||||
declare let Zone: any;
|
||||
|
||||
/**
|
||||
* @whatItDoes Represents the extra options used during navigation.
|
||||
|
@ -55,16 +55,13 @@ export interface NavigationExtras {
|
|||
* [{
|
||||
* path: 'parent',
|
||||
* component: ParentComponent,
|
||||
* children: [
|
||||
* {
|
||||
* children: [{
|
||||
* path: 'list',
|
||||
* component: ListComponent
|
||||
* },
|
||||
* {
|
||||
* },{
|
||||
* path: 'child',
|
||||
* component: ChildComponent
|
||||
* }
|
||||
* ]
|
||||
* }]
|
||||
* }]
|
||||
* ```
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue