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

43 lines
1.1 KiB
Dart
Raw Normal View History

2016-11-27 22:24:30 +00:00
import 'dart:html';
2021-05-14 07:02:50 +00:00
import 'package:angel3_route/browser.dart';
2016-11-27 22:24:30 +00:00
2021-04-03 05:50:52 +00:00
void basic(BrowserRouter router) {
2016-11-27 22:24:30 +00:00
final $h1 = window.document.querySelector('h1');
final $ul = window.document.getElementById('handlers');
router.onResolve.listen((result) {
2021-04-03 05:50:52 +00:00
final route = result.route;
2016-11-27 22:24:30 +00:00
2021-04-03 05:50:52 +00:00
// TODO: Relook at this logic
//if (route == null) {
// $h1!.text = 'No Active Route';
// $ul!.children
// ..clear()
// ..add(LIElement()..text = '(empty)');
//} else {
if ($h1 != null && $ul != null) {
$h1.text = 'Active Route: ${route.name}';
$ul.children
2016-11-27 22:24:30 +00:00
..clear()
2021-04-03 05:50:52 +00:00
..addAll(result.allHandlers
2019-11-28 17:40:32 +00:00
.map((handler) => LIElement()..text = handler.toString()));
2021-04-03 05:50:52 +00:00
} else {
print('No active Route');
2016-11-27 22:24:30 +00:00
}
2021-04-03 05:50:52 +00:00
//}
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
}