Skip to content

Add "when" property to the Fallback component #44

@webJose

Description

@webJose

The when property on the Route component didn't go well. It created a lot of confusion and got ultimately removed.

However, I believe it has good potential on the Fallback component.

Motivation

This library is a multi-route-matching router library. This complicates things for fallback content. For example, having an always-matching route (because of inexact path matching, for example) could leave the developer without a fallback option at all. Let's remember that multi-route-matching is a desired feature because it opens more possibilities for micro-frontend mounting. However, the more this feature is used, the less space there is for the Fallback component.

To mitigate this problem, the Route component has exchanged the when property with the ignoreForFallback property. This helps.

It is not inconceivable, however, that more complex scenarios could appear, and that simply leaving one or 2 routes out of the calculation for fallback content may not be enough.

Proposal

In code:

<Fallback when={(rs) => ... }>
  ...
</Fallback>

Where rs is the route status information from the parent router. What does this do? It forgoes the dependency on the parent router's noMatches property: If a Fallback component is given the when predicate function, fallback content will be shown if the predicate returns true, regardless of the router's noMatches property.

We could even expand the parameters to receive the value of noMatches:

<Fallback when={(rs, noMatches) => ... }>
  ...
</Fallback>

Then developers can decide what information to use to fine-tune the inclusion of the fallback content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: HighHigh priority. Downvote to attempt to lower priority.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions