loading...

Call for JavaScript library: "navigation history"

ben profile image Ben Halpern ・1 min read

Based on the discussion in this post:

We got on to this thread:

Maybe you are looking for window.history.length? UPD: just double checked, it doesn't subtract the number when you use back button :/

Maybe there's a way to do some programming magic and get that to work?

Between that and other persistence like localStorage etc, there is probably a technically possible way to make it happen. We only have to worry about on-site situations because this is for the standalone app.

This is a pretty generalizeable situation so if anyone wanted to build a library for this I'm all for it! 😄

I believe all the information about determining cangoback would exist in the information about past actions taken on the site and persisted in whichever way was called for.

If someone wants to take a stab at this, it would be really useful!

Discussion

pic
Editor guide
Collapse
isaacdlyman profile image
Isaac Lyman

Would this meet your needs?

npmjs.com/package/back-forward-his...

Based on the history library, it lets you set up a listener for state change events (including back/forward), and has a handy canGoBack() method. I haven't used it, but it seems like it would work for a PWA.

Collapse
ben profile image
Ben Halpern Author

Oh it just might be, I'll check it out in more detail tomorrow.

P.S. I owe you an email reply. I'll get to that tomorrow too 😊

Collapse
mortoray profile image
edA‑qa mort‑ora‑y

Oh my, I spent over a year at my last job making a history system that was state aware and could support such navigation requests. It was for mobile though, not web -- the web one I did five years ago. That tech has probably been replaced about 10 times by now in the web world. :D

Collapse
darkain profile image
Vincent Milum Jr

github.com/browserstate/history.js/

It's old, outdated. But it does work with all desktop and mobile browsers I've ever tried. Though their own notes say anything modern should just use the native APIs.

Collapse
ben profile image
Ben Halpern Author

Of course, if this already exists, let me know! 😄

Collapse
link2twenty profile image
Andrew Bone

I'd like to know too 😁