11import { distinctUntilChanged , filter , map , take } from 'rxjs/operators' ;
2- import { Injectable } from '@angular/core' ;
3- import { ActivatedRoute , NavigationEnd , Params , Router , RouterStateSnapshot , } from '@angular/router' ;
2+ import { Inject , Injectable } from '@angular/core' ;
3+ import { ActivatedRoute , NavigationEnd , ParamMap , Params , Router , RouterStateSnapshot , } from '@angular/router' ;
44
55import { combineLatest , Observable } from 'rxjs' ;
66import { createSelector , MemoizedSelector , select , Store } from '@ngrx/store' ;
@@ -12,6 +12,7 @@ import { hasValue } from '../../shared/empty.util';
1212import { historySelector } from '../history/selectors' ;
1313import { AddUrlToHistoryAction } from '../history/history.actions' ;
1414import { CoreState } from '../core-state.model' ;
15+ import { NativeWindowRef , NativeWindowService } from './window.service' ;
1516
1617/**
1718 * Selector to select all route parameters from the store
@@ -63,7 +64,7 @@ export function parameterSelector(key: string, paramsSelector: (state: CoreState
6364 providedIn : 'root'
6465} )
6566export class RouteService {
66- constructor ( private route : ActivatedRoute , private router : Router , private store : Store < CoreState > ) {
67+ constructor ( private route : ActivatedRoute , private router : Router , private store : Store < CoreState > , @ Inject ( NativeWindowService ) private _window : NativeWindowRef ) {
6768 this . saveRouting ( ) ;
6869 }
6970
@@ -141,9 +142,14 @@ export class RouteService {
141142
142143 public getQueryParamMap ( ) : Observable < any > {
143144 return this . route . queryParamMap . pipe (
144- map ( ( paramMap ) => {
145+ map ( ( paramMap : ParamMap ) => {
145146 const snapshot : RouterStateSnapshot = this . router . routerState . snapshot ;
146147 // Due to an Angular bug, sometimes change of QueryParam is not detected so double checks with route snapshot
148+ if ( ! ( this . _window . nativeWindow . location . href || '' ) . includes ( '?' ) ) {
149+ // Prevent sending outdated query params
150+ const emptyParamMap : ParamMap = { keys : [ ] , has : ( name : string ) => false , get : ( name : string ) => null , getAll : ( name : string ) => [ ] } ;
151+ return emptyParamMap ;
152+ }
147153 if ( ! isEqual ( paramMap , snapshot . root . queryParamMap ) ) {
148154 return snapshot . root . queryParamMap ;
149155 } else {
0 commit comments