github statelyai/xstate xstate@5.28.0

9 hours ago

Minor Changes

  • #4184 a741fe7 Thanks @davidkpiano! - Added routable states. States with route: {} and an explicit id can be navigated to from anywhere via a single { type: 'xstate.route', to: '#id' } event.

    const machine = setup({}).createMachine({
      id: 'app',
      initial: 'home',
      states: {
        home: { id: 'home', route: {} },
        dashboard: {
          initial: 'overview',
          states: {
            overview: { id: 'overview', route: {} },
            settings: { id: 'settings', route: {} }
          }
        }
      }
    });
    
    const actor = createActor(machine).start();
    
    // Route directly to deeply nested state from anywhere
    actor.send({ type: 'xstate.route', to: '#settings' });

    Routes support guards for conditional navigation:

    settings: {
      id: 'settings',
      route: {
        guard: ({ context }) => context.role === 'admin'
      }
    }

Patch Changes

Don't miss a new xstate release

NewReleases is sending notifications on new releases.