MCPcopy
hub / github.com/ampproject/amphtml / navigateTo

Method navigateTo

examples/pwa/pwa.js:128–164  ·  view source on GitHub ↗

* @param {string} path * @return {!Promise}

(path)

Source from the content-addressed store, hash-verified

126 * @return {!Promise}
127 */
128 navigateTo(path) {
129 log('Navigate to: ', path);
130 const oldPage = this.currentPage_;
131 this.currentPage_ = path;
132
133 // Update URL.
134 const push = !isShellUrl(path) && isShellUrl(oldPage);
135 if (path != this.win.location.pathname) {
136 if (push) {
137 this.win.history.pushState(null, '', path);
138 } else {
139 this.win.history.replaceState(null, '', path);
140 }
141 }
142
143 if (isShellUrl(path)) {
144 log('Back to shell');
145 this.ampViewer_.clear();
146 return Promise.resolve();
147 }
148
149 // Fetch.
150 const url = this.resolveUrl_(path);
151 log('Fetch and render doc:', path, url);
152 // TODO(dvoytenko, #9490): Make `streamDocument` the only used API once
153 // streaming is graduated out of experimental.
154 if (this.useStreaming_) {
155 log('Streaming started: ', url);
156 return this.ampViewer_
157 .showAsStream(url)
158 .then((shadowDoc) => streamDocument(url, shadowDoc.writer));
159 }
160 return fetchDocument(url).then((doc) => {
161 log('Fetch complete: ', doc);
162 return this.ampViewer_.show(doc, url);
163 });
164 }
165
166 /**
167 * @param {string} url

Callers 10

constructorMethod · 0.95
handleNavigate_Method · 0.95
handlePopState_Method · 0.95
test-navigation.jsFile · 0.45
handleBlocked_Method · 0.45
onClick_Method · 0.45
maybeHandleRedirect_Method · 0.45

Calls 12

resolveUrl_Method · 0.95
isShellUrlFunction · 0.85
streamDocumentFunction · 0.85
pushStateMethod · 0.80
replaceStateMethod · 0.80
resolveMethod · 0.80
showAsStreamMethod · 0.80
logFunction · 0.70
fetchDocumentFunction · 0.70
clearMethod · 0.65
thenMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected