route icon indicating copy to clipboard operation
route copied to clipboard

Use memory for storage?

Open bminer opened this issue 11 months ago • 6 comments

It would be cool if an option existed to use memory to store the router state, as a substitute for history.pushState. Any ideas for how this could be accomplished? I'm happy to submit a PR if you think this is worthwhile.

bminer avatar Jan 14 '25 19:01 bminer

That can be handled by using the router stream. For example:

import { router } from '@riotjs/route'

router.on.value(cacheTheRoutes)

The router object is an erre sream so you should be able to hook your callbacks using the erre API

GianlucaGuarini avatar Jan 17 '25 22:01 GianlucaGuarini

Agreed, but how do you tell the Riot components to use that instead?

bminer avatar Jan 25 '25 21:01 bminer

Just following up to see if there is an option for the riot HOC route or router to use memory for storage rather than history.pushState. Is there an example of this somewhere? If it's possible, I'd like to work on this.

bminer avatar Feb 04 '25 02:02 bminer

I am not sure if I understand your question but if you want to handle the route links and store them by yourself you might have a look at this example https://plnkr.co/edit/syfuyLhXNoWlWqZ0 If you want to use a memory router similar to the react router, that's not yet possible

GianlucaGuarini avatar Feb 14 '25 22:02 GianlucaGuarini

The memory link example you sent me is quite useful, but I am hoping for a more plug-and-play solution that automatically listens for <a> tags being clicked -- a bit like React router.

If you think this is worthwhile, I would be happy to give it a try and submit a PR. I can foresee a few changes to dom.js

bminer avatar Feb 19 '25 18:02 bminer

@bminer yeah sure I accept PRs. Let me see what you mean and if the code will still be manageable I will be happy to merge it. Thank you

GianlucaGuarini avatar Feb 21 '25 19:02 GianlucaGuarini