我需要调用API并验证数据,然后根据API的结果我需要重新路由用户。所有这些都应该在页面渲染之前发生。
我正在以角度5工作
validateUrl() {
this.route.params.subscribe(async params => {
if (params['id']) {
let rep = await this.validateRepUrl(params['id']);
if (rep) {
this.router.navigate(['/request', rep]);
} else {
this.router.navigate(['/']);
}
}
});
}
validate(url) {
let validationDone;
const updated = new Promise<Boolean>(resolve => validationDone = resolve);
this.startupService.validateUrl(url)
.subscribe(result => {
if (result && result.data > 0) {
validationDone(result.data);
}
}, err => {
validationDone(null);
});
}