mirror of
https://github.com/asimonson1125/asimonson1125.github.io.git
synced 2026-02-25 05:09:49 -06:00
simulate Single Page App with websockets
This commit is contained in:
@@ -87,3 +87,26 @@ function toggleMenu() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let socket = io();
|
||||
|
||||
function emit(event) {
|
||||
socket.emit(event);
|
||||
}
|
||||
|
||||
function emitData(event, data) {
|
||||
socket.emit(event, data)
|
||||
}
|
||||
|
||||
socket.on('goto', (page) => {
|
||||
pagename = page[0];
|
||||
content = page[1];
|
||||
let root = document.getElementById('root');
|
||||
root.innerHTML = content;
|
||||
root.querySelectorAll("script").forEach(x => {
|
||||
eval(x.innerHTML);
|
||||
});
|
||||
document.querySelector('title').textContent = page[2];
|
||||
if (pagename == 'home') pagename = '/';
|
||||
history.pushState(null, null, pagename);
|
||||
});
|
||||
Reference in New Issue
Block a user