angel3_route 8.2.0 copy "angel3_route: ^8.2.0" to clipboard
angel3_route: ^8.2.0 copied to clipboard

A powerful, isomorphic routing library for Dart. It is mainly used in the Angel3 framework, but can be used in Flutter and on the Web.

example/main.dart

import 'dart:math';

import 'package:angel3_route/angel3_route.dart';

void main() {
  final router = Router();

  router.get('/whois/~:user', () {});

  router.get('/wild*', () {});

  router.get('/ordinal/int:n([0-9]+)st', () {});

  print(router.resolveAbsolute('/whois/~thosakwe').first.allParams);
  print(router.resolveAbsolute('/wild_thornberrys').first.route.path);
  print(router.resolveAbsolute('/ordinal/1st').first.allParams);

  router.get('/users', () {});

  router.post('/users/:id/timeline', (String id) {});

  router.get('/square_root/:id([0-9]+)', (String n) {
    return {'result': pow(int.parse(n), 0.5)};
  });

  // You can also have parameters auto-parsed.
  //
  // Supports int, double, and num.
  router.get('/square_root/int:id([0-9]+)', (int n) {
    return {'result': pow(n, 0.5)};
  });

  router.group('/show/:id', (router) {
    router.get('/reviews', (id) {
      return someQuery(id).reviews;
    });

    // Optionally restrict params to a RegExp
    router.get('/reviews/:reviewId([A-Za-z0-9_]+)', (id, reviewId) {
      return someQuery(id).reviews.firstWhere((r) => r.id == reviewId);
    });
  });
}

SomeQuery someQuery(id) => SomeQuery();

class SomeQuery {
  List<SomeQueryReview> get reviews => [
        SomeQueryReview('fake'),
        SomeQueryReview('data'),
      ];
}

class SomeQueryReview {
  final String id;

  SomeQueryReview(this.id);
}
2
likes
160
points
4.64k
downloads

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

A powerful, isomorphic routing library for Dart. It is mainly used in the Angel3 framework, but can be used in Flutter and on the Web.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

belatuk_combinator, path, string_scanner

More

Packages that depend on angel3_route