Skip to content

Configuration

root()

root() — returns struct

Available in: mapper Category: Routing

Create a route that matches the root of its current context. This mapper can be used for the application’s web root (or home page), or it can generate a route for the root of a namespace or other path scoping mapper. The route only responds to the GET verb unless you explicitly pass a method (or methods) argument.

NameTypeRequiredDefaultDescription
tostringno—Set controller##action combination to map the route to. You may use either this argument or a combination of controller and action.
mapFormatbooleanno—Set to true to include the format (e.g. .json) in the route.
<cfscript>

// 1. Map the application's web root (home page) to a specific controller action
mapper()
    // Map "/" to the `index` action of the `home` controller
    .root(to="home##index")
.end();

// 2. Map the root of a namespace scope using separate controller and action arguments
mapper()
    .namespace("admin")
        // Map "/admin/" to the `dashboard` action of the `admin` controller
        .root(controller="admin", action="dashboard")
    .end()
.end();

// 3. Map the root with format matching enabled so ".json" etc. are captured
mapper()
    .namespace("api")
        // Map "/api/" and "/api/.json" (etc.) to the `apis` controller's `index` action
        .root(to="apis##index", mapFormat=true)
    .end()
.end();

</cfscript>