use method

  1. @override
void use(
  1. String path,
  2. Middleware map
)
override

Adds a middleware function to the router.

The path defines the route pattern. Segments starting with : (e.g., :id) are treated as parameters. The map function transforms matched route values during lookup, without modifying the stored routes.

Example (apply logging middleware to all routes under /api):

final router = RelicRouter()
  ..get('/api/users', listUsers)
  ..get('/api/users/:id', getUser)
  // `use` accepts a mapping function. For handlers, this matches `Middleware`.
  ..use('/api', logRequests());

Example (apply auth middleware only to /admin/*):

final router = RelicRouter()
  ..get('/admin/dashboard', adminDashboard)
  ..use('/admin', authMiddleware());

Implementation

@override
void use(final String path, final Middleware map) =>
    inject(_Injectable((final r) => r.use(path, map)));