Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
Guards and redirects
Sometimes a navigation should not proceed as-is: an unauthenticated user hitting /dashboard should be sent
to /login, a renamed page should redirect, or a half-filled form should warn before you leave. rune
handles these with route guards, server redirects, and before-unload rules.
Route guards (client redirect rules)
A route can carry a guard in its meta. When you register the route, the guard is serialized into the
client route table (__routes[].guard), so the client router can redirect before rendering the guarded
page:
The guard's redirect is the destination the router sends the user to when the route should not be shown.
Combine it with an auth atom: the guard names the fallback, your app decides (from state) whether to apply
it. A common pattern is to check an auth atom in the page/layout and navigate("/login") when it is empty,
the guard's redirect is the declarative companion the router knows about up front.
Server-side redirects
For redirects that must happen on the server (SEO-friendly 301/302, moved pages, canonical hosts), handle them in an API route or middleware and send a redirect response:
Or register middleware that inspects the request and short-circuits with a redirect for a class of URLs (see Middleware).
Conditional rendering vs redirecting
For UI-level gating you do not always need a redirect, you can render different content based on an atom:
Use a guard/redirect when the URL itself should change (so the back button and shareable links behave correctly); render conditionally when you just want to swap the content in place.
Back-button rules and before-unload guards
The router config (toClientConfig) carries two advanced controls baked into the page as __routerConfig:
backRules, declarative rules for what the browser Back button should do for certain paths: match a
path (by string or regex) and either goTo a specific route or skip the entry. Useful for flows where
"back" should not return to an intermediate step (e.g. a payment confirmation).
beforeUnload, guards that run before a navigation/unload, so you can warn the user about unsaved
changes.
The router's beforeUnload config is the framework-level hook for the in-app navigation case (the
beforeunload event covers hard reloads/closes).
Choosing the right tool
| You want to... | Use |
|---|---|
| Send unauthenticated users away from a page | a route guard: { redirect: "/login" } + an auth atom |
| 301/302 a moved or canonical URL | a server redirect (API route / middleware) |
| Show a different UI without changing the URL | conditional rendering on an atom |
| Control what Back does in a flow | router backRules |
| Warn about unsaved changes | a before-unload guard |
Next: generating routes from data, Programmatic routes.