RoutingRule

sealed trait RoutingRule[Page, Props]

A single routing rule. Intended to be composed with other RoutingRules. When all rules are composed, this is turned into a RoutingRule.WithFallback instance.

Type parameters:
Page

The type of legal pages. Most commonly, a sealed trait that you've created, where all subclasses represent a page in your SPA.

Companion:
object
class Object
trait Matchable
class Any
class Atom[Page, Props]
class AutoCorrect[Page, Props]
class Conditional[Page, Props]
class ConditionalP[Page, Props]
class Or[Page, Props]

Value members

Abstract methods

def modPath(onCreate: Path => Path, onParse: Path => Option[Path]): RoutingRule[Page, Props]

Modify the path(es) generated and parsed by this rule.

Modify the path(es) generated and parsed by this rule.

Value parameters:
onCreate

Modify paths when generating for a route.

onParse

When parsing a path, transform and optionally reject it.

def pmapF[W](f: Page => W)(g: W => Option[Page]): RoutingRule[W, Props]
def xmap[A](f: Page => A)(g: A => Page): RoutingRule[A, Props]

Concrete methods

final def addCondition[G[_]](condition: G[Boolean])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds.

Prevent this rule from functioning unless some condition holds.

Value parameters:
condition

Sync[Unit] that requested page and returns true if the page should be rendered.

final def addConditionBy[G[_]](condition: Page => G[Boolean])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context.

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context.

Value parameters:
condition

Function that takes the requested page and returns true if the page should be rendered.

final def addConditionWithFallback[G[_]](condition: G[Boolean], fallback: Action[Page, Props])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, a fallback action is performed.

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, a fallback action is performed.

Value parameters:
condition

Sync[Unit] that requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold.

final def addConditionWithFallbackBy[G[_]](condition: Page => G[Boolean], fallback: Action[Page, Props])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, a fallback action is performed.

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, a fallback action is performed.

Value parameters:
condition

Function that takes the requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold.

final def addConditionWithOptionalFallback[G[_]](condition: G[Boolean], fallback: Page => Option[Action[Page, Props]])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, an optional fallback action may be performed.

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, an optional fallback action may be performed.

Value parameters:
condition

Sync[Unit] that requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold. If response is None it will be as if this rule doesn't exist and will likely end in the route-not-found fallback behaviour.

final def addConditionWithOptionalFallback[G[_]](condition: G[Boolean], fallback: Option[Action[Page, Props]])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, an optional fallback action may be performed.

Prevent this rule from functioning unless some condition holds. When the condition doesn't hold, an optional fallback action may be performed.

Value parameters:
condition

Sync[Unit] that requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold. If response is None it will be as if this rule doesn't exist and will likely end in the route-not-found fallback behaviour.

final def addConditionWithOptionalFallbackBy[G[_]](condition: Page => G[Boolean], fallback: Page => Option[Action[Page, Props]])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, an optional fallback action may be performed.

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, an optional fallback action may be performed.

Value parameters:
condition

Function that takes the requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold. If response is None it will be as if this rule doesn't exist and will likely end in the route-not-found fallback behaviour.

final def addConditionWithOptionalFallbackBy[G[_]](condition: Page => G[Boolean], fallback: Option[Action[Page, Props]])(implicit G: Sync[G]): RoutingRule[Page, Props]

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, an optional fallback action may be performed.

Prevent this rule from functioning unless some condition holds, passes in the page requested as part of the context. When the condition doesn't hold, an optional fallback action may be performed.

Value parameters:
condition

Function that takes the requested page and returns true if the page should be rendered.

fallback

Response when rule matches but condition doesn't hold. If response is None it will be as if this rule doesn't exist and will likely end in the route-not-found fallback behaviour.

final def autoCorrect: RoutingRule[Page, Props]
final def autoCorrect(redirectVia: SetRouteVia): RoutingRule[Page, Props]

When a route matches a page, compare its Path to what the route would generate for the same page and if they differ, redirect to the generated one.

When a route matches a page, compare its Path to what the route would generate for the same page and if they differ, redirect to the generated one.

Example: If a route matches /issue/dev-23 and returns a Page("DEV", 23) for which the generate path would be /issue/DEV-23, this would automatically redirect /issue/dev-23 to /issue/DEV-23, and process /issue/DEV-23 normally using its associated action.

final def fallback(fallbackPath: Page => Path, fallbackAction: (Path, Page) => Action[Page, Props]): WithFallback[Page, Props]

Specify behaviour when a Page doesn't have an associated Path or Action.

Specify behaviour when a Page doesn't have an associated Path or Action.

final def noFallback: WithFallback[Page, Props]

When a Page doesn't have an associated Path or Action, throw a runtime error.

When a Page doesn't have an associated Path or Action, throw a runtime error.

This is the trade-off for keeping the parsing and generation of known Pages in sync - compiler proof of Page exhaustiveness is sacrificed.

It is recommended that you call RouterConfig.verify as a sanity-check.

final def pmap[W](f: Page => W)(pf: PartialFunction[W, Page]): RoutingRule[W, Props]
final def pmapCT[W](f: Page => W)(implicit ct: ClassTag[Page]): RoutingRule[W, Props]
final def prefixPath(prefix: String): RoutingRule[Page, Props]

Add a prefix to the path(es) generated and parsed by this rule.

Add a prefix to the path(es) generated and parsed by this rule.

final def prefixPath_/(prefix: String): RoutingRule[Page, Props]

Add a prefix to the path(es) generated and parsed by this rule.

Add a prefix to the path(es) generated and parsed by this rule.

Unlike prefixPath when the suffix is non-empty, a slash is added between prefix and suffix.

final def widen[W >: Page](pf: PartialFunction[W, Page]): RoutingRule[W, Props]
final def widenCT[W >: Page](implicit ct: ClassTag[Page]): RoutingRule[W, Props]
final def widenF[W >: Page](f: W => Option[Page]): RoutingRule[W, Props]
final def |(that: RoutingRule[Page, Props]): RoutingRule[Page, Props]

Compose rules.

Compose rules.