lightning-js / blits

The Lightning 3 App Development Framework
Apache License 2.0
58 stars 9 forks source link

Implemented router before hook #83

Closed suresh-gangumalla closed 3 months ago

suresh-gangumalla commented 3 months ago

The router before hook has access to router path parameters in the order they are defined in the router path.

The following cases are covered under router before hook

michielvandergeest commented 3 months ago

As discussed today offline, I’ve been thinking a bit about this feature and perhaps the before hook should receive 2 arguments: the route object for the route we’re navigating to and the route we’re navigation from (before(to, from))

This allows for doing something conditional in the before hook based on where we’re navigating from.

The second benefit is that we can do changes to the route object we’re navigating to (i.e. inject a different component, add / change props, etc.) and return that object as the result of the before hook. If the route object is returned it will be used in the next step of the router.

For basic redirection to a different route, I guess we can continue to return a string

Please take a look at how feasible this change is and whether there are things unclear or unexpected issue arise.