diff --git a/lib/browser.dart b/lib/browser.dart index 0bcdbc70..a2e860ea 100644 --- a/lib/browser.dart +++ b/lib/browser.dart @@ -43,6 +43,7 @@ abstract class BrowserRouter extends Router { } abstract class _BrowserRouterImpl extends Router implements BrowserRouter { + bool _listening = false; Route _current; StreamController _onResolve = new StreamController(); @@ -83,6 +84,16 @@ abstract class _BrowserRouterImpl extends Router implements BrowserRouter { $a.attributes['dynamic'] = 'true'; } } + + void _listen(); + + @override + void listen() { + if (_listening) + throw new StateError('The router is already listening for page changes.'); + _listening = true; + _listen(); + } } class _HashRouter extends _BrowserRouterImpl { @@ -121,7 +132,7 @@ class _HashRouter extends _BrowserRouterImpl { } @override - void listen() { + void _listen() { window.onHashChange.listen(handleHash); handleHash(); } @@ -184,7 +195,7 @@ class _PushStateRouter extends _BrowserRouterImpl { } @override - void listen() { + void _listen() { window.onPopState.listen((e) { handleState(e.state); }); diff --git a/lib/src/route.dart b/lib/src/route.dart index 276b3367..98e1f2f1 100644 --- a/lib/src/route.dart +++ b/lib/src/route.dart @@ -354,7 +354,7 @@ class Route { for (int i = 0; i < matches.length && i < values.length; i++) { Match match = matches.elementAt(i); String paramName = match.group(1); - String value = values.elementAt(i); + String value = Uri.decodeComponent(values.elementAt(i)); // _printDebug('Setting param "$paramName" to "$value"...'); result[paramName] = value; } diff --git a/lib/src/router.dart b/lib/src/router.dart index dfa1e42a..0097cf25 100644 --- a/lib/src/router.dart +++ b/lib/src/router.dart @@ -253,7 +253,8 @@ class Router { : segments.join('/'); } - /// Assigns a middleware to a name for convenience. + /// Manually assign via [requestMiddleware] instead. + @deprecated registerMiddleware(String name, middleware) { requestMiddleware[name] = middleware; } diff --git a/pubspec.yaml b/pubspec.yaml index c5aceb5f..8fb732f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_route description: A powerful, isomorphic routing library for Dart. -version: 1.0.7 +version: 1.0.8 author: Tobe O homepage: https://github.com/angel-dart/angel_route dev_dependencies: diff --git a/test/root_test.dart b/test/root_test.dart new file mode 100644 index 00000000..b9dc95eb --- /dev/null +++ b/test/root_test.dart @@ -0,0 +1,15 @@ +import 'package:angel_route/angel_route.dart'; +import 'package:test/test.dart'; + +void main() { + test('resolve / on /', () { + var router = new Router() + ..group('/', (router) { + router.group('/', (router) { + router.get('/', 'ok'); + }); + }); + + expect(router.resolveAbsolute('/'), isNotNull); + }); +} diff --git a/test/uri_decode_test.dart b/test/uri_decode_test.dart new file mode 100644 index 00000000..0674b22a --- /dev/null +++ b/test/uri_decode_test.dart @@ -0,0 +1,18 @@ +import 'package:angel_route/angel_route.dart'; +import 'package:test/test.dart'; + +void main() { + test('uri params decoded', () { + var router = new Router()..get('/a/:a/b/:b', ''); + + var encoded = + '/a/' + Uri.encodeComponent('<<<') + '/b/' + Uri.encodeComponent('???'); + print(encoded); + var result = router.resolveAbsolute(encoded); + print(result.allParams); + expect(result.allParams, { + 'a': '<<<', + 'b': '???', + }); + }); +}