Created
September 3, 2019 19:07
-
-
Save sebastianrothbucher/7a373bed0c924a6654402006f84bc5f6 to your computer and use it in GitHub Desktop.
mini pushstate demo (npm run start)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script> | |
function doMagic() { | |
event.preventDefault(); | |
fetch('page2.json').then(res => res.json()).then(res => { | |
Object.keys(res).forEach(k => document.getElementById(k).textContent=res[k]); | |
history.pushState({}, null, "page2.html"); | |
}); | |
} | |
</script> | |
<h1 id="hOne">Headline index</h1> | |
<p id="para">Content index <a href="page2.html" onclick="doMagic()">go to page2</a></p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "pushstate", | |
"version": "1.0.0", | |
"dependencies": {}, | |
"devDependencies": { | |
"http-server": "0.11.1" | |
}, | |
"scripts": { | |
"prestart": "npm install", | |
"start": "http-server ." | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1 id="hOne">Headline page2</h1> | |
<p id="para">Content page2 (via Server)</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"hOne": "Headline page2", | |
"para": "Content page2 (via JSON)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment