1

I'm using this code to redirect this.router.navigate(['/abc']);. How to show some message on the new page using <ngb-alert>, Is it possible to pass some variable while redirecting but not as url query parameters?

ore ore
  • 79
  • 1
  • 2
  • 6

2 Answers2

6

You can do that with State as below:

When you want to navigate set state:

const navigationExtras: NavigationExtras = {state: {data: 'This is an example'}};
this.router.navigate(['/abc'], navigationExtras);

In destination component you can get data like the following:

data:string;
constructor(private router: Router) { 
   const navigation = this.router.getCurrentNavigation();
   const state = navigation.extras.state as {data: string};
   this.data = state.data;
}
Abolfazl Roshanzamir
  • 12,730
  • 5
  • 63
  • 79
0

You can use a service to pass data from one component to another without using route parameters at all.

Their is already a datailed topic about this. Send data through routing paths in Angular