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

Method handleNavigate_

examples/pwa/pwa.js:84–114  ·  view source on GitHub ↗

* @param {!Event} e

(e)

Source from the content-addressed store, hash-verified

82 * @param {!Event} e
83 */
84 handleNavigate_(e) {
85 if (e.defaultPrevented) {
86 return false;
87 }
88 if (e.button) {
89 return false;
90 }
91 let a = e.target;
92 while (a) {
93 if (a.tagName == 'A' && a.href) {
94 break;
95 }
96 a = a.parentElement;
97 }
98 if (a) {
99 const url = new URL(a.href);
100 const {location} = this.win;
101 if (
102 url.origin == location.origin &&
103 startsWith(url.pathname, '/pwa/') &&
104 url.pathname.indexOf('amp.html') != -1
105 ) {
106 e.preventDefault();
107 const newPage = url.pathname + location.search;
108 log('Internal link to: ', newPage);
109 if (newPage != this.currentPage_) {
110 this.closeSidebar().then(() => this.navigateTo(newPage));
111 }
112 }
113 }
114 }
115
116 handlePopState_() {
117 const newPage = this.win.location.pathname;

Callers

nothing calls this directly

Calls 5

closeSidebarMethod · 0.95
navigateToMethod · 0.95
startsWithFunction · 0.70
logFunction · 0.70
thenMethod · 0.45

Tested by

no test coverage detected