trie_router 2.1.2 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);
}