77 */
88
99import { LocationChangeEvent , LocationChangeListener , PlatformLocation } from '@angular/common' ;
10- import { Inject , Injectable } from '@angular/core' ;
10+ import { Inject , Injectable , Optional } from '@angular/core' ;
1111import { DOCUMENT } from '@angular/platform-browser' ;
1212import { Subject } from 'rxjs/Subject' ;
1313import * as url from 'url' ;
1414
1515import { scheduleMicroTask } from './facade/lang' ;
1616import { getDOM } from './private_import_platform-browser' ;
17+ import { INITIAL_CONFIG , PlatformConfig } from './tokens' ;
1718
1819
1920
@@ -28,7 +29,16 @@ export class ServerPlatformLocation implements PlatformLocation {
2829 private _hash : string = '' ;
2930 private _hashUpdate = new Subject < LocationChangeEvent > ( ) ;
3031
31- constructor ( @Inject ( DOCUMENT ) private _doc : any ) { }
32+ constructor (
33+ @Inject ( DOCUMENT ) private _doc : any , @Optional ( ) @Inject ( INITIAL_CONFIG ) _config : any ) {
34+ const config = _config as PlatformConfig | null ;
35+ if ( ! ! config && ! ! config . url ) {
36+ const parsedUrl = url . parse ( config . url ) ;
37+ this . _path = parsedUrl . pathname ;
38+ this . _search = parsedUrl . search ;
39+ this . _hash = parsedUrl . hash ;
40+ }
41+ }
3242
3343 getBaseHrefFromDOM ( ) : string { return getDOM ( ) . getBaseHref ( this . _doc ) ; }
3444
@@ -59,7 +69,7 @@ export class ServerPlatformLocation implements PlatformLocation {
5969 replaceState ( state : any , title : string , newUrl : string ) : void {
6070 const oldUrl = this . url ;
6171 const parsedUrl = url . parse ( newUrl , true ) ;
62- this . _path = parsedUrl . path ;
72+ this . _path = parsedUrl . pathname ;
6373 this . _search = parsedUrl . search ;
6474 this . setHash ( parsedUrl . hash , oldUrl ) ;
6575 }
0 commit comments