Rocon Website

RootRouteBuilder

type RootRouteBuilder<
  ActionResult,
  WildcardFlag extends WildcardFlagType,
  Match
>

The Root route builder is a route builder that defines a route with a fixed location. It is useful when your app is deployed to a deep location like /path/to/your/app/, in which case you can create a Root route builder with path /path/to/your/app and attach other routes under it.

A Root route builder always holds one route record that represents a route with the specified location.

Initiaization

Rocon.Root(
  options?: RootRouteBuilderOptions
): RootRouteBuilder<...>

type RootRouteBuilderOptions = {
  root?: Location;
};

Creates a new instance of Root route builder. It has one route defined from first which has no action at first. To define a route with action, use the action method.

Example

// Define a route for /path/to/your/app/?key=wow
const builder = Rocon.Root({
  root: {
    pathname: "/path/to/your/app",
    search: "?key=wow",
    state: null
  }
});

builder.action(func)

action(
  action: ActionType<ActionResult, Match>
): RootRouteBuilder<...>

Returns a new Root route builder whose single route has an action associated to it.

builder.attach(otherBuilder)

attach: AttachFunction<ActionResult, Match>

Alias of builder.route.attach(otherBuilder). Attaches otherBuilder to this builder's route and returns otherBuilder.

Example

// Define two routes corresponding to /path/to/your/app/foo and
// /path/to/your/app/bar
const routes = Rocon.Root({
  root: {
    pathname: "/path/to/your/app",
    state: null
  }
}).attach(Rocon.Path())
  .routes({
    foo: {
      action: () => <p>This is foo</p>
    },
    bar: {
      action: () => <p>This is bar</p>
    },
  });

builder.route

The route record defined by this Root route builder.