kitze / mobx-router

A simple router for MobX + React apps
509 stars 66 forks source link

History Manipulation #22

Open eugenkiss opened 7 years ago

eugenkiss commented 7 years ago

Great work on this project! I've created a similar project (https://github.com/eugenkiss/static-mobx-routing) and I'm comparing the different approaches we took to see if there are things to improve.

Consider the following use case. You are on the homepage (/). You enter the route /new-post and create a new post. This leads you to route /post/12. When you now press the browser's back button you go back directly to / instead of /new-post. The reason I find this intuitive is that the new post became the post with the id 12 and therefore it makes sense to replace the history entry /new-post after successfully having created a post. You can see this working in my demo project: http://static-mobx-routing.surge.sh/

How would you suggest implementing this use case with mobx-router?

kitze commented 7 years ago

Hey man! Your router looks amazing! I would looove if we can brainstorm on this because I needed it in few of my projects. Ping me on twitter @thekitze and let me know when can we chat.

eugenkiss commented 7 years ago

Will do! For general information purposes, here's the rough idea: Routes are part of a list (the history) that is (de)serializable and there is a pointer/index that points to the current route in the history. This pointer moves according to the user's history manipulation (e.g. pressing the back button decreases the by 1). You can manipulate this list however you please.