platform/packages/route/web/shared/basic.dart

38 lines
965 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) {
2021-03-18 00:11:45 +00:00
$h1!.text = 'No Active Route';
$ul!.children
2016-11-27 22:24:30 +00:00
..clear()
2019-11-28 17:40:32 +00:00
..add(LIElement()..text = '(empty)');
2016-11-27 22:24:30 +00:00
} else {
2021-03-18 00:11:45 +00:00
$h1!.text = 'Active Route: ${route.name ?? route.path}';
$ul!.children
2016-11-27 22:24:30 +00:00
..clear()
2021-03-18 00:11:45 +00:00
..addAll(result!.allHandlers
2019-11-28 17:40:32 +00:00
.map((handler) => LIElement()..text = handler.toString()));
2016-11-27 22:24:30 +00:00
}
});
router.get('a', 'a handler');
router.group('b', (router) {
2017-11-27 02:21:19 +00:00
router.get('a', 'b/a handler').name = 'b/a';
router.get('b', 'b/b handler', middleware: ['b/b middleware']).name = 'b/b';
2016-11-27 22:24:30 +00:00
}, 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
}