From f4cfdf0a5b7a84d40d3fdccda92cddab71c0e57a Mon Sep 17 00:00:00 2001 From: Fabiano Taioli Date: Tue, 5 Oct 2021 11:44:16 +0200 Subject: [PATCH] Control page change with a key in state Currently any new history change trigger a page component regeneration. Sometimes may be helpful to update the url without trigger a page component recalc. Proposed solution use a key attribute in the history object state. If a key is present and the key of the new state is equal to the key of the old state the page component recalc is not triggered. --- src/RouterSource.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/RouterSource.ts b/src/RouterSource.ts index 3bb120a..1b8902d 100644 --- a/src/RouterSource.ts +++ b/src/RouterSource.ts @@ -59,7 +59,16 @@ export class RouterSource { const _createHref = this._createHref; const createHref = util.makeCreateHref(namespace, _createHref); - return this._history$ + return this._history$.fold( + ({ last }, actual) => ({ + last: actual, + out: last?.state?.key && last?.state?.key === actual?.state?.key ? undefined : actual + }), + { + last: undefined, + out: undefined + } + ).filter(v => !!v.out).map(v => v.out) .map((location: Location) => { const matcher = routeMatcher || this._routeMatcher; const filteredPath = getFilteredPath(