angular - How to render angular4 universal with query parameter route -


i'm trying migrate angular 1.4 angular4 universal seo purposes. works well. have 1 route.

confirm email after registration http://localhost/confirmemail/09393?code='xxxxxxxxx'

ngoninit() {      let param_id = this.route.snapshot.params['id'];     let param_code = this.route.snapshot.queryparams['code'];     this.message = '';      this.authservice.getconfirmation(param_id, param_code)         .subscribe(             data => {               this.router.navigate(['/login']);             },             error => {              }         );   } 
  1. looks gets rendered on server , calls rest api getconfirmation.
  2. once ui rendered on client calls getconfirmation again.

is there way. don't wanna call rest api server side, call client code.

this worked me.

check see if global window object present. call rest api confirmed

ngoninit() {

  if (typeof window !== 'undefined') {       let param_id = this.route.snapshot.params['id'];       let param_code = this.route.snapshot.queryparams['code'];       this.message = '';       this.getconfirmation(param_id, param_code);   } 

}


Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -