trie_router 2.1.2 copy "trie_router: ^2.1.2" to clipboard
trie_router: ^2.1.2 copied to clipboard

A Trie-based route parsing package

trie_router #

A Trie-based route parser.

Usage #

import 'package:trie_router/trie_router.dart';

typedef RouteHandler = void Function(Map<String, String> parameters);

TrieRouter router = TrieRouter<RouteHandler>();

void main() {
  // Add routes
  addRoute('', (_) => print('Displaying home page'));
  addRoute('users/:id', (params) => print('Displaying user ${params[":id"]}'));
  addRoute('users/:id/settings',
      (params) => print('Displaying settings for user ${params[":id"]}'));

  // Handle routes
  handlePath('');
  handlePath('users/123');
  handlePath('users/123/settings');
}

void addRoute(String s, RouteHandler handler) {
  router.add(s, handler);
}

void handlePath(String s) {
  var element = router.get(s);
  element.value(element.parameters);
}
2
likes
140
pub points
51%
popularity

Publisher

unverified uploader

A Trie-based route parsing package

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, path, quiver

More

Packages that depend on trie_router