Nue’s routing model has one rule: your file system is your URL structure. A Markdown file atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nuejs/nue/llms.txt
Use this file to discover all available pages before exploring further.
blog/hello-world.md becomes the page at /blog/hello-world. An index.md or index.html at any level becomes that directory’s root URL. There is no router configuration file to maintain and no framework-specific conventions to learn.
File-based routing
ThegetURL function in file.js implements the URL derivation rule directly:
.mdand.htmlfiles drop their extension in the URL- Files named
indexproduce the directory URL (e.g.,blog/index.md→/blog/) - TypeScript files (
.ts) are served as.js - All other files keep their extension
Directory structure example
How index files become page routes
Anindex.md or index.html at any directory level becomes the page for that directory path. When Nue serves a URL without a file extension (e.g., /blog/), it looks for index.html or <dirname>/index.html among the site assets:
index.html that acts as the application shell — important for multi-application sites where different sections may have different layouts or navigation.
Multi-page app organization
Nue supports organizing multiple applications within one site. Each top-level directory is treated as a separate application with its own configuration:app.yaml file for per-application configuration (layouts, CSS, collections) that merges with the global site.yaml. The @shared/ directory holds assets available to all applications.
SPA routing with nuestate
Single-page application routing is handled by nuestate. Rather than a dedicated router package, nuestate treats the URL itself as the source of truth for application state. Theautolink feature intercepts <a href> clicks and converts them to SPA navigation without a full page reload.
Enable autolink in your state setup:
autolink: true, nuestate attaches a click listener to the document. When a user clicks an <a href> that matches the configured route pattern, it calls api.set() instead of following the link, updates the URL via history.pushState, and fires any registered state listeners:
metaKey, ctrlKey) are respected so that “open in new tab” still works.
Dynamic route parameters
Route parameters are path segments prefixed with: in the route pattern. Nuestate parses them from the URL and makes them available as state properties:
getPathData function matches a URL pathname against a route template and extracts the named parameters:
undefined, signaling no match. This is what the autolink handler uses to decide whether to intercept a click.
Rendering path-based URLs
When state changes cause route parameters to update, nuestate re-renders the URL usingrenderPath:
/products/shoes rather than /products/shoes/undefined.
Server routes
Server-side route handlers live in the@shared/server/ directory by default (configurable via server.dir in site.yaml). The entry point is @shared/server/index.js, which defines routes using the nue-edgeserver API.
@shared/server/data/ as JSON files. The createEnv function in model.js loads each JSON file as a typed model:
users.json file automatically gets a UserModel with login, logout, and authenticate methods. All other JSON files get a basic CRUD model with getAll, get, create, and update/remove via the returned item object.
Server routes are reloaded automatically during development when you edit files in
@shared/server/. The createWorker function accepts a reload option that re-imports the route module on each request.State storage contexts
Beyond the URL, nuestate supports multiple storage contexts for different kinds of state:path_params
URL path segments like
/app/:section. Changes trigger history.pushState with a full path update.query
URL query parameters like
?search=shoes. Changes trigger history.replaceState on the search string.session
sessionStorage — persists for the browser tab session. Cleared when the tab closes.local
localStorage — persists across sessions. Use for user preferences like theme or language.localStorage → sessionStorage → URL search → URL path → in-memory. Writing to any property automatically routes to the correct storage.