-
Notifications
You must be signed in to change notification settings - Fork 154
/
pages.js
32 lines (30 loc) · 964 Bytes
/
pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const products = {
porsche: { name: "Porsche-Diesel Master 419", img: "porsche.svg" },
fendt: { name: "Fendt F20 Dieselroß", img: "fendt.svg" },
eicher: { name: "Eicher Diesel 215/16", img: "eicher.svg" }
};
class DecidePages extends HTMLElement {
connectedCallback() {
this.render(window.location);
this.unlisten = window.appHistory.listen(location =>
this.render(location)
);
}
render(location) {
console.log("route change (second level / decide)");
const match = location.pathname.match("/product/(.*)");
const product = match && products[match[1]];
if (product) {
this.innerHTML = `
<a href="/">< home</a> -
<a href="/checkout/cart">view cart ></a>
<h1>${product.name}</h1>
<img src="https://mi-fr.org/img/${product.img}" width="200">
`;
}
}
disconnectedCallback() {
this.unlisten();
}
}
window.customElements.define("decide-pages", DecidePages);