Router.navigate doesn't work in angular app

Mohammed Ajmal

I have the following code to perform http PUT:

updateProduct(form: any) {
  this.productService.updateProduct(form, this.id).subscribe(
    (data: any) => data
  );
  this.route.navigate(['']);
}

service.ts:

 updateProducts(productForm, id) {


  const temp = {
        'description': productForm.description,
        'quality': productForm.quality
    };
    return this.httpObj.put(`${this.uri}/products/${id}`, JSON.stringify(temp), {
        headers: new HttpHeaders({
            'Content-Type': 'application/json'
        })
});
}

The problem is that I am able to perform the update operation but the submit button doesn't route to the home route.

Sajeetharan

You need to place the router.navigate within the subscribe,

updateProduct(form: any) {
  this.productService.updateProduct(form, this.id).subscribe((data: any) => (
     this.route.navigate(['']);
 )};
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why my router navigate function doesn't work in angular 8?

angular 2 router.navigate doesn't work with electron IPC callback

Angular router doesn't navigate for the first time from component to component

this.router.navigate() doesn't navigate to the URL

Angular 2 router navigation doesn't work

Angular 4, Router 4.0.0: routerLink or router.navigate programatically doesn't redirect to child routes

Angular 5 router.navigate does not work

Backbone router.navigate doesn't redirect

Router navigate doesn't save url after navigate

Angular router won't navigate in http interceptor

Angular2 - named router-outlet doesn't navigate to component with child route

Angular router navigate doesn't load page when query parameters change

<router-outlet> doesn't work in Angular 9

Angular ui router - Redirection doesn't work at all

Angular 6 Router Transition Animation doesn't work (Nav bar)

Why doesn't this nested angular-ui-router work?

Angular 8 Nested routes and multiple router outlet doesn't work

navigate('/') doesn't navigate

React Router doesn't work

ui router doesn't work

Why doesn't router.push({pathname: 'somewhere', query: {id: 1234}}) work on app router?

angular router navigate then reload

angular 2 router hybrid app: url reverts back after navigate

Angular2 router.navigate reloads app

Router.navigate problems in ionic-angular app

Navigate in react router 6 doesn't redirect to another page

Why the 2nd part in this Angular app doesn't work?

Angular App doesn't work when injecting a pagination dependency

Routing doesn't work after Dockerizing Angular app