* @param {string} path * @return {!Promise}
(path)
| 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 |
no test coverage detected