From 3934761f1d49d8baf9f1ed63e407d0c143d37ad3 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 26 Apr 2017 16:57:21 -0700 Subject: [PATCH] Expose route matching function so that it can be more easily externally integrated --- lib/src/router.dart | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/src/router.dart b/lib/src/router.dart index 7e3a3c3..21c8992 100644 --- a/lib/src/router.dart +++ b/lib/src/router.dart @@ -46,16 +46,24 @@ class Router { return match?.route ?? notFoundRoute; } - /// used by the [MaterialApp.onGenerateRoute] function as callback to - /// create a route that is able to be consumed. - Route generator(RouteSettings routeSettings) { - AppRouteMatch match = _routeTree.matchRoute(routeSettings.name); + Route matchRoute(String path, {RouteSettings routeSettings = null}) { + RouteSettings settingsToUse = routeSettings; + if (routeSettings == null) { + settingsToUse = new RouteSettings(name: path); + } + AppRouteMatch match = _routeTree.matchRoute(path); AppRoute route = match?.route ?? notFoundRoute; if (route == null) { return null; } Map parameters = match?.parameters ?? {}; - return route.routeCreator(routeSettings, parameters); + return route.routeCreator(settingsToUse, parameters); + } + + /// used by the [MaterialApp.onGenerateRoute] function as callback to + /// create a route that is able to be consumed. + Route generator(RouteSettings routeSettings) { + return matchRoute(routeSettings.name, routeSettings: routeSettings); } /// Prints the route tree so you can analyze it.