问题
I'm trying to migrate angular 1.4 to angular4 universal for SEO purposes. Everything works well. I have one 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 => {
}
);
}
- Looks like it gets rendered on the server and calls rest API getConfirmation.
- once UI is rendered on the client it calls getconfirmation again.
Is there a way. I don't wanna call the rest API server side, just call it from the client code.
回答1:
this worked for me.
check to see if global window object is present. then call rest api to get 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);
}
}
来源:https://stackoverflow.com/questions/45788326/how-to-render-angular4-universal-with-query-parameter-route