Angular query params when refreshing Page

1k Views Asked by At

I have an issue, that is struggling me. Scenario - Page A and Page B:

  • In Page A I have a button that navigate to Page B adding a query params
this.router.navigate(['asignaturas', 2, 'datosgenerales'], {queryParams: {edit: false}}); 
  • Page B is loaded correctly. BUT if I click refresh in browser i got an error
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'asignaturas/2/datosgenerales%3Fedit%3Dfalse'
Error: Cannot match any routes. URL Segment: 'asignaturas/2/datosgenerales%3Fedit%3Dfalse'

The URL is adding the query params also. That I wouldn't like to.

  • I tried to check when is page reload with this code and recreate the navigation
 ngOnInit() {
    this.browserRefresh = browserRefresh; // Give true | false if is page refresh
    if(this.browserRefresh) {
      this.router.navigate(['asignaturas/2/datosgenerales'], {queryParams: {edit: true}});
    }

Even trying to recreate the url, it still throw me the error. It there a way to fix it, or ignore the query params

0

There are 0 best solutions below