Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

router.navigate doesn't work

I have tried to redirect the page after getting data successfully deleted. So I put the redirect router.navigate inside of the subscribe of the data section. But it's not working and also I have tried with ngZone also nothing happens. And I want to show the success message also. How can I show that?

without ngZone:

  const rid = params['rid'];
        this.roleSer.deleteRole(rid).subscribe(

            data => { this.router.navigate(['viewroles']) },
            error => { error }
        );
    });

with ngZone:

const vrid = this.route.params.subscribe((params: Params) => {
        const rid = params['rid'];
        this.roleSer.deleteRole(rid).subscribe(
            data => { this.zone.run(()=>{
                 this.router.navigate(['viewroles']) 
            }); },
            error => { error }
        );
    });
like image 267
Kevin - Dhinesh babu Avatar asked May 29 '26 17:05

Kevin - Dhinesh babu


1 Answers

Create one redirect function and use it

const vrid = this.route.params.subscribe((params: Params) => {
            const rid = params['rid'];
            this.roleSer.deleteRole(rid).subscribe(
                data => { 
                    this.redirect('viewroles');
                },
                error => { error }
            );
        });

    redirect(path): void {
     this.router.navigate(['/' + path]) 
    }
like image 61
Shailesh Ladumor Avatar answered Jun 01 '26 07:06

Shailesh Ladumor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!