Search code examples
angularionic-framework

how to properly redirect to another page after post request in ionic angular?


I'm trying to redirect to another page after user sign up in ionic angular but i'm getting nothing code below:

    this.http.post('http://127.0.1.1:3001/api/signup',user)
        .subscribe({
            next: (res) => {if(res == "OK"){this.router.navigateByUrl("/otp")}},
            error: error => console.error(error),
            complete: () => this.router.navigateByUrl("/otp")
   });

Solution

  • you could do something like

        .subscribe((res) => {
            if (res == "OK") {
              this.router.navigate(['otp']);
            } else {
              this.errmsgshow = true;
              this.errmsg = res.msg;
            }