Login

Language :
TitleAngular Universal 환경에서 document.referrer 개체를 사용하는 방법(팁)
How to use the document.referrer object in an Angular Universal environment.
Writer이지섭Write DateFeb 27 2019Modify DateMay 5 2022View Count3579

This is how to use the document.referrer object in an Angular Universal environment.

 

import { Inject, PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';

@Component({
  selector: 'app-board-view',
  templateUrl: './board-view.component.html',
  styleUrls: ['./board-view.component.css']
})
export class BoardViewComponent implements OnInit {
  
  constructor(
    //....
    @Inject(PLATFORM_ID) private platformId
  ) { }

  ngOnInit() {
    let referrer = "";
    if (!isPlatformServer(this.platformId)) {
      referrer = document.referrer;
    }
  }

}

 

At runtime, according to the execution value of "isPlatformServer(this.platformId)",

in Angular Universal , which runs on a server, a document object of javascript is not referred to,

but only in the client's browser, the document object is referred to.

 

This allows the viewing of source from the server end to run normally,

and allows the browser client to program using the document.referrer object.

 

If you use a JavaScript document object in Angular Universal,

it will not be SSR (Server Side Rendering).

 

It's a little incomplete.

Comment

Name               Password 
Content
Check Password.

Please enter your password when registering your comment.