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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -