Skip to content

Routing

When serving a directory, Nubo builds routes from files in that directory.

Terminal window
nubo serve app

A file ending in .nubo is executable.

app/
index.nubo
about.nubo

Routes:

FileRoute
app/index.nubo/
app/about.nubo/about

The .nubo extension is removed from the URL.

Files named index.nubo become the folder route.

app/
index.nubo
docs/
index.nubo

Routes:

FileRoute
app/index.nubo/
app/docs/index.nubo/docs

Use square brackets for route parameters.

app/
users/
[id].nubo

Route:

/users/123

Inside users/[id].nubo, read the parameter with request.param.

import request from "@server/request"
import response from "@server/response"
let id = request.param("id")
response.write("User ID: ")
response.write(id)

Nubo prefers exact matches before dynamic parameter matches.

app/
users/
settings.nubo
[id].nubo

Routes:

URLMatched File
/users/settingsusers/settings.nubo
/users/123users/[id].nubo

Files that do not end in .nubo are not executed. They are served as static files.

app/
index.nubo
style.css
logo.png

Routes:

FileBehavior
index.nuboExecuted by Nubo.
style.cssServed as a static file.
logo.pngServed as a static file.

If no route matches, Nubo tries built-in static files. If that fails, the request becomes a 404 Not Found.

If your app has an error.nubo file, Nubo can use it as a custom error page.