I need pass a param from one route to other but it should not visible to user. I need it in Angular 6.
Asked
Active
Viewed 729 times
-1
-
1If it shouldn't be in the URL, you can't pass it as a query or path parameter. – jonrsharpe Jul 11 '18 at 07:05
-
you can use @Input decorater and pass the value through that variable. – Abhishek Jaiswal Jul 11 '18 at 07:16
-
You can hold the value in service. – Vignesh Jul 11 '18 at 07:18
-
I has variable from response and need to pass it to another ts component to where it routes to next step and at the same time i don't want to view that variable on the url. – Madhavi Jul 11 '18 at 09:05
2 Answers
0
You could use matrix params.
Then using the Angular location, and router services, to read and then overwrite the URL history.
It isn't elegant but works..and achieves what you asked.
Example for the check and re-write of location history:
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => {
const matrixParams = this.location.path().split(';');
... do something with the matrixParam
if(matrixParams.length > 1) {
this.location.replaceState(matrixParams[0])
}
}));
Other ideas (as mentioned):
- Use a service to pass the data around, check for it in OnInit
- As mentioned, pass it between components using @Input()

Jmsdb
- 515
- 3
- 9