Loading
API REFERENCE
defineRouter() is an utility function that allows you to define a router by attaching pages to it and setting a layout and other options.
tsximport { RouterComponent, defineRouter } from "rasengan"; import AppLayout from "@/app/app.layout"; import Home from "@/app/home.page"; import About from "@/app/about.page"; class AppRouter extends RouterComponent {} export default defineRouter({ imports: [], layout: AppLayout, pages: [Home, About], })(AppRouter);
defineRouter accepts an object with the following options:
| Option | Type | Description | Optional |
|---|---|---|---|
| imports | RouterComponent[] | An array of other Router classes to be imported. | Yes |
| layout | LayoutComponent | The layout component to be used. | Yes |
| pages | PageComponent[] | An array of page components to be used. | No |
| notFoundComponent | React.FC | The 404 page component to be used. | Yes |
| loaderComponent | React.FC | The loader component to be used. | Yes |
useParentLayout | boolean | Whether to use the parent layout or not. | Yes |
defineRouter returns a function that accepts a Router class and returns a new Router instance object with the options defined.