DEV Community

Discussion on: Build a Single Page Application (SPA) Site With Vanilla.js

Collapse
 
vbilopav profile image
vbilopav

Do you have any idea how to implement hash-less routing on the client? I've tried and I failed.

Collapse
 
jeremylikness profile image
Jeremy Likness ⚡️

Good question! I'll explore that. There are libraries that handle it but I will look into a pure source solution.

Collapse
 
joeyguerra profile image
Joey Guerra

Do you mean with window.history? (developer.mozilla.org/en-US/docs/W...)

Collapse
 
vbilopav profile image
vbilopav

Yes, probably by manipulating window history

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I have my successful solution here. Might write an article later.

GitHub logo patarapolw / minimal-rollup-ts-pug-sass-template

Rollup + TypeScript + Pug + SASS template with no plan for JavaScript frameworks, whatsoever

In short, more than history.pushState, you also need window.dispatchEvent(new PopStateEvent('popstate', { state: { to } })); if you don't have history.go.

Now, you can listen to popstate events.