router library
Lark Router — File-based routing system.
Import separately to enable tree-shaking when not using routing.
Classes
- BlankLayout
- A layout that just renders the page without wrapping.
- Layout
- Base class for layouts that wrap pages.
- MiddlewareRunner
- Middleware runner that executes a chain of middleware.
- Controls navigation flow in middleware.
- Route
- Represents a route in the application.
- RouteCollection
- Route collection for matching.
- RouteDefinition
- Defines a route with path pattern and builder.
- RouteMatch
- Result of matching a URL against a route.
- Router
- The application router.
- RouterComponent
- A component that renders the matched route's component.
- RouterLink
- A link that navigates via the router without reloading the page.
- RouterOutlet
- A component that renders the nested route based on the current depth.
Functions
-
getMiddleware(
String name) → MiddlewareFn? - Gets a registered middleware by name.
-
getMiddlewareList(
List< String> names) → List<MiddlewareFn> - Gets multiple middleware by names.
-
registerMiddleware(
String name, MiddlewareFn middleware) → void - Registers a named middleware.
-
route(
String path, Component builder(Map< String, String> params), {String? name, List<String> middleware = const [], List<RouteDefinition> children = const [], FutureOr<Object?> loader(RouteMatch match)?, Map<String, dynamic> meta = const {}}) → RouteDefinition - Creates route definitions.
-
runWithRouter<
T> (Future< T> fn(Router router)) → Future<T> - Run a function with an isolated Router instance.
-
useParams(
) → Map< String, String> - Returns route params (reactive via route).
-
useQueryParams(
) → Map< String, String> - Returns query params (reactive via route).
-
useRoute(
) → Route - Returns the current route (reactive).
-
useRouter(
) → Router - Returns the router instance.
-
useRouteRef(
) → Ref< Route> - Returns the current route as a reactive ref.
Typedefs
- MiddlewareFn = void Function(Route to, Route from, NavigationControl next)
- A function that guards route navigation.