Migration Guide
Transitioning to Sirou from a traditional router like React Router or Next.js Link is straightforward. The primary shift is moving from Path-Based Navigation to Schema-Based Navigation.
From React Router
| React Router | Sirou |
|---|---|
<Link to="/user/123"> |
<SirouLink to="user" params={{ id: '123' }}> |
navigate('/settings') |
router.go('settings') |
useParams() |
useRouteParams('routeName') |
useEffect data fetching |
loader in route config |
Step-by-Step Migration
- Define your routes: Take your existing
<Route />components and map their paths into aroutes.tsfile. - Replace Link components: Slowly swap out
<Link />for<SirouLink />. - Encapsulate Logic: Move authorization logic from
useEffectinto Sirou Guards.
From Next.js
Sirou is fully compatible with Next.js. You can use Sirou purely for its URL Generation and Type Inference while keeping Next.js for rendering.
The Conversion
tsx
// Instead of this:
<Link href={`/blog/${post.slug}`}>...</Link>;
// Use this:
import { getUrl } from "@sirou/next";
<Link href={getUrl("blog.post", { slug: post.slug })}>...</Link>;Breaking Changes from v0.x
defineSchemarenamed todefineRoutes.router.navigateTorenamed torouter.go.metais now strictly typed via the generic parameter indefineRoutes.
Need help? Open an issue on GitHub or check the Roadmap for upcoming compatibility features.
