Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore query params when back browser button is pressed

Tags:

angular

I have three tabs in my dashboard components. When any tab is clicked url is appended with queryParam with tab info (say root/dashboard?tab=tab1). If users clicked on multiple tabs and then presses back button, queryParams of previous tabs are shown, rightfully so.

However, I want to router to ignore all the queryParams and navigate to the previous route (say root/profiles).

How to do this in Angular?

like image 304
dasfdsa Avatar asked Dec 17 '25 12:12

dasfdsa


1 Answers

On your router link you need to set the replaceUrl property to true. This will cause any links clicked to replace the current browser history location with the current link.

<a [routerLink]="['./']" replaceUrl="true" [queryParams]="{tab: 'tab1'}">Tab1</a>
<a [routerLink]="['./']" replaceUrl="true" [queryParams]="{tab: 'tab2'}">Tab2</a>
<a [routerLink]="['./']" replaceUrl="true" [queryParams]="{tab: 'tab3'}">Tab3</a>
like image 187
Teddy Sterne Avatar answered Dec 19 '25 06:12

Teddy Sterne