RefactKit uses TanStack Router’s file-based routing system to map the filesystem directly to your URL structure. Every file you create insideDocumentation Index
Fetch the complete documentation index at: https://docs.refactkit.com/llms.txt
Use this file to discover all available pages before exploring further.
src/routes/ becomes a route — no manual registration required. The _app/organizations/$slug/ subtree is where all organization-scoped pages live, and understanding its conventions will let you ship new workspace features quickly and correctly.
Route structure overview
Thesrc/routes/ directory is organized into three logical zones:
| Directory | Purpose |
|---|---|
_auth/ | Public routes: login, signup, password reset |
_app/ | Authenticated shell: sidebar layout, settings |
_app/organizations/$slug/ | Organization workspace pages |
_ prefix makes _app and _auth pathless layout routes — they wrap their children in a layout component without adding a URL segment.
Create a page inside an organization workspace
Every organization page lives undersrc/routes/_app/organizations/$slug/. The $slug segment is a dynamic parameter that TanStack Router populates automatically from the URL.
Create the route file
Add a new file at
src/routes/_app/organizations/$slug/my-page.tsx. The filename becomes the URL segment — this file will be served at /organizations/acme/my-page.Define the route export
Every route file must export a
Route constant created with createFileRoute. Pass the full route path as a type-safe string literal:Read parent loader data
The$slug layout route at src/routes/_app/organizations/$slug/route.tsx loads the organization and the current user’s role before any child route renders. Import its Route export to access that data:
/organizations if it does not:
Protect routes with beforeLoad
Use beforeLoad to verify session state or enforce role requirements before any rendering occurs. Throwing a redirect from beforeLoad prevents the loader and component from ever running.
beforeLoad and redirect non-owners:
The
_app root layout already verifies the session in its own loader and redirects to /login if there is none. Child routes benefit from this automatically — but you should still use beforeLoad for role-specific restrictions.SSR best practices: seed the cache with ensureQueryData
RefactKit renders pages on the server before sending them to the browser. To avoid a second network round-trip during hydration, seed the TanStack Query cache inside your route loader using ensureQueryData:
ensureQueryData only fetches if the data is not already in the cache — it is safe to call multiple times. Once the page hydrates in the browser, useQuery picks up the pre-filled cache and renders instantly without a loading state.
Search parameter validation
If your page needs query string parameters, validate them with avalidateSearch function so TanStack Router infers their types:
Reactivity when switching organizations
When a user switches between organizations in the sidebar, the$slug param changes and the loaders re-run automatically. To prevent stale local state from leaking across organizations, key your page container on the organization ID:

