MCPcopy Create free account
hub / github.com/ampproject/amphtml / replaceStateForTarget

Method replaceStateForTarget

src/service/history-impl.js:164–172  ·  view source on GitHub ↗

* Helper method to handle navigation to a local target, e.g. When a user * clicks an anchor link to a local hash - Go to section * 1 . * * @param {string} target * @return {!Promise}

(target)

Source from the content-addressed store, hash-verified

162 * @return {!Promise}
163 */
164 replaceStateForTarget(target) {
165 devAssert(target[0] == '#', 'target should start with a #');
166 const previousHash = this.ampdoc_.win.location.hash;
167 return this.push(() => {
168 this.ampdoc_.win.location.replace(previousHash || '#');
169 }).then(() => {
170 this.binding_.replaceStateForTarget(target);
171 });
172 }
173
174 /**
175 * Get the fragment from the url or the viewer.

Callers 2

test-history.jsFile · 0.45
handleHashNavigation_Method · 0.45

Calls 4

pushMethod · 0.95
devAssertFunction · 0.90
thenMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected