-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
92 lines (82 loc) · 2.18 KB
/
index.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title>O.js Example</title>
<style>
.nav-link {
cursor: pointer;
text-decoration: underline;
color: blue;
}
</style>
</head>
<body>
<nav>
<a class="nav-link" data-route="">Home</a>
<a class="nav-link" data-route="about">About</a>
<a class="nav-link" data-route="contact">Contact</a>
<a class="nav-link" data-route="feedback">Feed Back</a>
</nav>
<div id="app"></div>
<script src="src/o.js"></script>
<script>
class HomeComponent extends OComponent {
constructor(element) {
super(element);
this.data = {
title: 'Home',
content: 'This is the home page.'
};
}
}
class AboutComponent extends OComponent {
constructor(element) {
super(element);
this.data = {
title: 'About',
content: 'This is the about page.'
};
}
}
class ContactComponent extends OComponent {
constructor(element) {
super(element);
this.data = {
title: 'Contact',
content: 'This is the contact page.'
};
}
}
class FeedBackComponent extends OComponent {
constructor(element) {
super(element);
this.data = {
title: 'Customer Feed Back',
content: 'This is my customer feedback page.'
};
}
}
o.component('HomeComponent', HomeComponent);
o.component('AboutComponent', AboutComponent);
o.component('ContactComponent', ContactComponent);
o.component('FeedBackComponent', FeedBackComponent);
o.route('', 'HomeComponent');
o.route('about', 'AboutComponent');
o.route('contact', 'ContactComponent');
o.route('feedback', 'FeedBackComponent');
o.setDefaultRoute('HomeComponent');
o.mount(() => {
o.navigate('');
// Add event listeners to the navigation links
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', (event) => {
const route = event.target.dataset.route;
o.navigate(route);
event.preventDefault();
});
});
});
</script>
</body>
</html>