Introduction
The problem
Modern.js gives you excellent file-based routing on top of React Router v7 — but navigation is stringly-typed:
Next.js has typedRoutes, React Router has typegen, SvelteKit has $types, TanStack Router is
typed end-to-end. Modern.js has… an open feature request.
The solution
modernjs-typed-routes is a Modern.js CLI plugin that reads the framework's own parsed route
tree and generates a single declaration file. Combined with the typed wrappers it ships, you get:
How it works
- During
modern dev/modern build(ornpx modern typegen), the plugin taps Modern.js's route generation and receives the fully-parsed route tree — including config routes frommodern.routes.tsand every entry of a multi-entry app. - It emits one file (default
src/routes.gen.d.ts) containing only types: a map of every route path to its params, merged into the package'sRegisterinterface via declaration merging. - The wrappers you import (
Link,Navigate,useNavigate, …) are static generic code that infers everything fromRegister. No runtime code is ever generated, and your bundle stays the same.
Because the types come from Modern.js's own parser — not a re-implementation of its conventions — they can't drift from what the framework actually serves.
Comparison
Requirements & compatibility
Routing must use conventional routes/ entries. Not supported: Modern.js v2, the legacy
pages/ convention, and self-controlled (App.tsx) entries — there's no conventional route tree
to type.