platform/web/shared/basic.dart

38 lines
962 B
Dart
Raw Normal View History

2016-11-27 22:24:30 +00:00
import 'dart:html';
import 'package:angel_route/browser.dart';
basic(BrowserRouter router) {
final $h1 = window.document.querySelector('h1');
final $ul = window.document.getElementById('handlers');
router.onResolve.listen((result) {
final route = result?.route;
if (route == null) {
$h1.text = 'No Active Route';
$ul.children
..clear()
..add(new LIElement()..text = '(empty)');
} else {
$h1.text = 'Active Route: ${route.name ?? route.path}';
$ul.children
..clear()
..addAll(result.allHandlers
.map((handler) => new LIElement()..text = handler.toString()));
}
});
router.get('a', 'a handler');
router.group('b', (router) {
router.get('a', 'b/a handler').as('b/a');
router.get('b', 'b/b handler', middleware: ['b/b middleware']).as('b/b');
}, middleware: ['b middleware']);
router.get('c', 'c handler');
2017-03-20 19:46:54 +00:00
router
..dumpTree()
..listen();
2016-11-27 22:24:30 +00:00
}