carloslfu / xstate-router

XState Router. Add routes to your XState machine.
MIT License
112 stars 16 forks source link

How can I prevent a route state to be entered if a condition is not met? #22

Closed juboba closed 4 years ago

juboba commented 4 years ago

I'm trying to do something like:

const Private = {
  entry: send ('test'),
...

But even though the event is emitted it does not transition the machine to the 'test' state.

The purpose of this is to prevent the user from entering the Private area if there is no valid token.

juboba commented 4 years ago

I was passing the wrong event name, sorry ^^'

joernroeder commented 4 years ago

my use case is a bit different as i am building a multi-step wizard form where you have to go through in a particular order. usually I would model this with https://xstate.js.org/docs/guides/transitions.html#transient-transitions and guards but how can I model this with router transitions in mind? If feels like adding entryConditions to the route definition at https://github.com/carloslfu/xstate-router/blob/master/src/index.tsx#L85 could work. entry/exit conditions per route (compared to the existing route-changed) could be cool in general.