routingkit 2.1.0 copy "routingkit: ^2.1.0" to clipboard
routingkit: ^2.1.0 copied to clipboard

Routing Kit - Lightweight and fast router. - A composable pure function routing kit.

example/main.dart

import 'package:routingkit/routingkit.dart';

void main() {
  final router = createRouter<String>();

  addRoute(router, 'get', '/path', 'Static path');
  addRoute(router, 'get', '/path/:name', 'Param route');
  addRoute(router, 'get', '/path/**', 'Wildcard route');
  addRoute(router, 'get', '/path/**:name', 'Named wildcard route');
  addRoute(
      router, 'get', '/files/:dir/:filename.:format,v:version', 'Mixed route');

  // Static
  final static = findRoute(router, 'get', '/path')?.lastOrNull;
  print('GET /path, ${static?.data}');

  // Param
  final paramRoute = findRoute(router, 'get', '/path/seven')?.lastOrNull;
  print(
    'GET /path/:name, ${paramRoute?.data}, name: ${paramRoute?.params.get('name')}',
  );

  // Wildcard
  final wildcard = findRoute(router, "get", "/path/foo/bar/baz")?.lastOrNull;
  print('GET /path/**, ${wildcard?.data}, ${wildcard?.params.catchall}');

  // Mixed
  print(findRoute(router, "GET", "/files/pubspec.yaml.dart,v1")
      ?.lastOrNull
      ?.data);
}
3
likes
160
pub points
26%
popularity

Publisher

verified publisherodroe.dev

Routing Kit - Lightweight and fast router. - A composable pure function routing kit.

Repository (GitHub)
View/report issues

Topics

#router #routing #route #fast-router #routing-kit

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

More

Packages that depend on routingkit