Home > Software engineering >  Redirecting an Angular app to another angular app
Redirecting an Angular app to another angular app

Time:09-15

I need to redirect one angular app to another if a certain thing is clicked while retaining a retailer number and a PO number for a specific return in the URL.

This is the kind of logic I have been trying to use but just can’t figure it out. Any ideas?

lk-grid-row (rowClick)="onRowClick($event)">

onRowClick(data: OrderStatus): void{ this.routeTo(/order-status/${data.orderNumber});

CodePudding user response:

You can use the router for any internal links:

export class MyComponent {
  constructor(private router: Router) {
  }

  onRowClick(data: OrderStatus): void {
    this.router.navigateByUrl(`/order-status/${data.orderNumber}`);
  }
}

If you need to redirect to another site use a dynamic [href] instead.

CodePudding user response:

So let's suppose we have two components 1-Component1 2-Component2

And we want to go form componet1 to component2 then

you have to define the route for the component that you want to redirect and then pass the variable to the route

You can declare the route something like this

const routes: Routes = [
{ path: 'component2/:retailerNo/:poNo', component: Component2} 

];

And then from the component where you want to redirect on any button click you can do something like this

1- Declare router in the constructor

2- onclick(){ this.router.navigate([component2/${this.retailerNo}/${this.poNo}]); }

P.S.= You should have the retailerNo and poNo in component1 and then in the component2 you will have to do these things

1- declare activated route in the constructor

and then you have too fetch the value

onInit(){
this.activatedRoute.params.subscribe(params => {
    this.reatilerNo = parseInt(params['retailerNo'])
    this.poNo = parseInt(params['poNo'])
})

}

  • Related