Rocon Website

PathSingleRouteInterface

type PathSingleRouteInterface<
  ActionResult,
  Match
>

Object passed to a callback function given to PathRouteBuilder#route. This object represents the route newly added by PathRouteBuilder#route.

p.action(func)

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

Defines an action for this route. If this method is called inside the callback function synchronously, the resulting route of PathRouteBuilder#route will have the given action. Returns p.

// Create a route for /foo and define an action for it.
const fooRoutes = Rocon.Path()
  .route("foo", (r) => r.action(() => <p>This is foo</p>));

r.attach(otherBuilder)

attach: AttachFunction<ActionResult, Match>

Attaches another route builder to this route. If this method is called inside the callback function synchronously, otherBuilder is attached to the resulting route of PathRouteBuilder#route. Returns otherBuilder.

Example

// Create a Search route buillder for /?foo=value.
const fooSearchRoute = Rocon.Search("foo")
  .action(({ foo }) => <p>The value of foo is {foo}</p>);

// Attach the builder to a route representing /app. 
// As a result, fooSearchRoute becomes a route for /app?foo=value.
const toplevelRoutes = Rocon.Path()
  .route("app", (r) => r.attach(fooSearchRoute));