I have router link like below:
<button class="take-a-tour-btn" [routerLink]="['/dashboard', {'showTour':'show'}]">
I want to pass parameter showTour
. But, when I do this, the parameter is visible in url
and I would like to hide it. I have gone through so many references(which says about optional parameters) ,but with no success in my case. How could I solve this?
@AddWeb @SailiUnique
Your solution works but you don't have to put the property in the [routLink]. The correct place is outside it as any property.
Like this:
<div class="row inline rowItem" [routerLink]="['/businessPartnerDetails']" [queryParams]="{ id: bpItem.id, bp: bpItem.companyName}" skipLocationChange=true (click)="onViewDetails(bpItem)">
The response isn't exactly efficient because the skipLocationChange don't change the current route on browser url and if you want to go back later, you backed from the first route.
For example if you were on home page and use this:
<button class="take-a-tour-btn" [routerLink]="['/dashboard', {'showTour':'show', skipLocationChange: true}]">Go to dashboard</button>
if you want to back from
dashboard
tohome
you can't do that with objectlocation
, in this case, you need to useRouter
and specify an exactly route (/dashboard
).But this in much cases this is a bad solution, and the browser routing don't change from
/home
todashboard
.Inconvenients:
dashboard
(current route)You can create the data service or check the official angular router docs
in Angular 7 you can use History state to pass dynamic data to the component you want to navigate to, without adding them into the URL, like so :
or
and you can get it this way
Try this in your component:(I am using it with Angular 5.x)
Try using skipLocationChange property.
I'm not sure, if there is a way to do it, because the data need to be presented in the URL string.
My suggestion is using global service which be store needed data. For example:
and use it in your navigation component in this way:
You will may use the same service in your Dashboard Component, and get needed value, f.e. in this way: