trie_router 2.0.0+1 copy "trie_router: ^2.0.0+1" to clipboard
trie_router: ^2.0.0+1 copied to clipboard

outdated

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
0
pub points
51%
popularity

Publisher

unverified uploader

A Trie-based route parsing package

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, path, quiver

More

Packages that depend on trie_router