keajs / kea

Batteries Included State Management for React
https://keajs.org/
MIT License
1.94k stars 51 forks source link

How to do something like router.pop() #155

Closed Arun-chaitanya closed 1 year ago

Arun-chaitanya commented 1 year ago

I can see I have actions like router.actions.push and router.actions.replace. But how to do POP action. Can you help @mariusandra

mariusandra commented 1 year ago

Sadly this is not possible. Not because of Kea, but since the browser's history api does not support this. Running window.history.back() might trigger it, but also not reliably if there's nothing in the history

Arun-chaitanya commented 1 year ago

Got it @mariusandra. Just a question though. In React Navigation, when you use the navigation.push() method to push a screen onto the stack and that screen is already present in the stack, it will result in a "stack reset." This means that all the screens above the duplicate screen in the stack will be removed (popped) from the stack, and the duplicate screen will appear as the topmost screen. Can we also provide an extra config option in our router.actions.push. Of course, it will be optional, and by default this can be false.

mariusandra commented 1 year ago

This seems like a pretty unique requirement, and unlike how navigation on the web works, so this likely shouldn't be part of the library. kea-router is just a light wrapper around the browser's history API, which does not tell you what pages the user visited.

The only real way I can think of doing this is:

All of my years in this industry say that implementing the above is a bad idea, full of various unobvious edge cases that will give you a bad time. This inadvertently means that I'm not going to implement this as part of the library, as that would mean I'd have to deal with all the edge cases and support requests on an ongoing basis.

You are free to implement all of this as part of your own app if you choose of course. I don't think you'd need to modify Kea for this.

Hope this helps somehow :).

Arun-chaitanya commented 1 year ago

@mariusandra thanks for this information. This was very insightful. I guess you can close the issue now.