Modified browser
This commit is contained in:
parent
1b22c8758a
commit
45d41c6dac
3 changed files with 18 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
# angel_route
|
||||
|
||||
![version 1.0.1](https://img.shields.io/badge/version-1.0.1-brightgreen.svg)
|
||||
![version 1.0.2](https://img.shields.io/badge/version-1.0.2-brightgreen.svg)
|
||||
![build status](https://travis-ci.org/angel-dart/route.svg)
|
||||
|
||||
A powerful, isomorphic routing library for Dart.
|
||||
|
|
|
@ -90,7 +90,7 @@ class _HashRouter extends _BrowserRouterImpl {
|
|||
|
||||
@override
|
||||
void listen() {
|
||||
window.onHashChange.listen((_) {
|
||||
void handleHash([_]) {
|
||||
final path = window.location.hash.replaceAll(_hash, '');
|
||||
final resolved = resolveAbsolute(path);
|
||||
|
||||
|
@ -101,7 +101,10 @@ class _HashRouter extends _BrowserRouterImpl {
|
|||
_onResolve.add(resolved);
|
||||
_onRoute.add(_current = resolved.route);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.onHashChange.listen(handleHash);
|
||||
handleHash();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,20 +133,26 @@ class _PushStateRouter extends _BrowserRouterImpl {
|
|||
|
||||
@override
|
||||
void listen() {
|
||||
window.onPopState.listen((e) {
|
||||
if (e.state is Map && e.state.containsKey('path')) {
|
||||
final resolved = resolveAbsolute(e.state['path']);
|
||||
void handleState(state) {
|
||||
if (state is Map && state.containsKey('path')) {
|
||||
final resolved = resolveAbsolute(state['path']);
|
||||
|
||||
if (resolved != null && resolved.route != _current) {
|
||||
properties.addAll(e.state['properties'] ?? {});
|
||||
properties.addAll(state['properties'] ?? {});
|
||||
_onResolve.add(resolved);
|
||||
_onRoute.add(_current = resolved.route
|
||||
..state.properties.addAll(e.state['params'] ?? {}));
|
||||
..state.properties.addAll(state['params'] ?? {}));
|
||||
}
|
||||
} else {
|
||||
_onResolve.add(null);
|
||||
_onRoute.add(_current = null);
|
||||
}
|
||||
}
|
||||
|
||||
window.onPopState.listen((e) {
|
||||
handleState(e.state);
|
||||
});
|
||||
|
||||
handleState(window.history.state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: angel_route
|
||||
description: A powerful, isomorphic routing library for Dart.
|
||||
version: 1.0.1
|
||||
version: 1.0.2
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/angel_route
|
||||
dev_dependencies:
|
||||
|
|
Loading…
Reference in a new issue