Skip to content

Commit 0fd5774

Browse files
authored
Merge pull request #474 from xthilakx/xthilakx/angular-universal-support
Angular Universal Compatibility for Server Side Rendering
2 parents 2e48bce + 16798b3 commit 0fd5774

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

projects/angular-token/src/lib/angular-token.service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Injectable, Optional, Inject } from '@angular/core';
1+
import { Injectable, Optional, Inject, PLATFORM_ID } from '@angular/core';
22
import { ActivatedRoute, Router, CanActivate } from '@angular/router';
33
import { HttpClient } from '@angular/common/http';
4+
import { isPlatformServer } from '@angular/common';
45

56
import { Observable, fromEvent, interval } from 'rxjs';
6-
import { pluck, filter, tap, share, finalize } from 'rxjs/operators';
7+
import { pluck, filter, share, finalize } from 'rxjs/operators';
78

89
import { ANGULAR_TOKEN_OPTIONS } from './angular-token.token';
910

@@ -53,9 +54,20 @@ export class AngularTokenService implements CanActivate {
5354
constructor(
5455
private http: HttpClient,
5556
@Inject(ANGULAR_TOKEN_OPTIONS) config: any,
57+
@Inject(PLATFORM_ID) private platformId: Object,
5658
@Optional() private activatedRoute: ActivatedRoute,
5759
@Optional() private router: Router
5860
) {
61+
if (isPlatformServer(platformId)) {
62+
window = {
63+
open: () => null,
64+
location: {
65+
href: '/',
66+
origin: '/'
67+
}
68+
} as Window;
69+
}
70+
5971
const defaultOptions: AngularTokenOptions = {
6072
apiPath: null,
6173
apiBase: null,

0 commit comments

Comments
 (0)