Introducing Halogen Router: One-stop-shop for managing routing in Halogen app

I would like to introduce halogen-router, routing management for Halogen apps. It’s my first PureScript library🎊!
Currently this library is not available via spago, but I’m waiting for The PR adding this library to the package-set is merged.

Compared to other JavaScript frontend libraries/frameworks like React or Vue.js, PureScript Halogen seems to have no out-of-the-box routing library.
There already are two great libraries for managing the routing: purescript-routing and purescript-routing-duplex, but to manage routing in halogen using these libraries, we still need to manage the subscription to the route changes and updating state holding route value by hand. So I have written my own.

To be honest, this library is just a thin adaptor between routing/routing-duplex and halogen :smile:


I’m very excited to announce that PR to the package-set has been merged and now this library is available via spago!


Thank you - finally no more copy&pasting from other projects for me :wink:


Haven’t read into it much, but is it possible to use your library in a project that does not use hooks?

1 Like

Thank you for commenting.

Currently, is it possible to use this library in components without hook, but it is a bit tedious because you need to write some boilerplately code to subscribe the emitter in the Initialize handler:

  type State = Maybe Route

  data Action = Initialize | RouteChanged Route | ...

  handleAction = case _ of
    Initialize -> do
      -- emitMatched is provided by MonadRouter class.
      emitter <- emitMatched
      void $ H.subscribe $ map RouteChanged emitter

    RouteChanged to -> do
      H.modify_ _ { current = Just to }

I think this is very disappointing, so I’m going to add purescript-halogen-store 's connect-like function in the next release, which is scheduled for this weekend :blush: