kitze / mobx-router

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

Async beforeEnter and beforeExit #24

Closed timkendall closed 6 years ago

timkendall commented 7 years ago

As documented in the Readme, allowing async beforeEnter and beforeExit hooks would be a nice feature to support.

I started implementing it here -> https://github.com/timkendall/mobx-router/tree/feat/async-hooks

While the basic implementation is done (needs test coverage), I did notice one edge case we will need to handle - if a route entry is scheduled, there needs to be a way to cancel it (i.e before the async hooks resolve).

Another issue to think about - should this lib keep track of if a route is in the "loading" state (i.e if an async hook is resolving)? Or should we letter consumers do that?

@kitze thoughts?

timkendall commented 7 years ago

Would be maybe cool to make the loading state available to the Link component at least? Then consumers could easily implement links that have loading indicators. This would in fact be useful also for routes that have been code split (if we ever implement that).

tomaash commented 6 years ago

I implemented this feature in a simpler way, just including async / await in the goTo function. Seems working so far. Until https://github.com/kitze/mobx-router/pull/56 get merged, feel free to use https://www.npmjs.com/package/mobx-router-3

kitze commented 6 years ago

Merged now