import { Inject , Injectable } from '@angular/core' ; import { RESPONSE } from '@nguniversal/express-engine/tokens' ; @ Injectable ( ) export class RedirectService { public redirect ( url ) { } } @ Injectable ( ) export class BrowserRedirectService extends RedirectService { redirect ( url ) { window . location . href = url ; } } @ Injectable ( ) export class ServerRedirectService extends RedirectService { constructor ( @ Inject ( RESPONSE ) private res ) { super ( ) ; } redirect ( url , permanent = false ) { const code = permanent ? 301 : 302 ; this . res . redirect ( code , url ) ; this . res . end ( ) ; } }