Expose route matching function so that it can be more easily externally integrated
This commit is contained in:
parent
3ebc12f7ff
commit
3934761f1d
|
@ -46,16 +46,24 @@ class Router {
|
||||||
return match?.route ?? notFoundRoute;
|
return match?.route ?? notFoundRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// used by the [MaterialApp.onGenerateRoute] function as callback to
|
Route<Null> matchRoute(String path, {RouteSettings routeSettings = null}) {
|
||||||
/// create a route that is able to be consumed.
|
RouteSettings settingsToUse = routeSettings;
|
||||||
Route<Null> generator(RouteSettings routeSettings) {
|
if (routeSettings == null) {
|
||||||
AppRouteMatch match = _routeTree.matchRoute(routeSettings.name);
|
settingsToUse = new RouteSettings(name: path);
|
||||||
|
}
|
||||||
|
AppRouteMatch match = _routeTree.matchRoute(path);
|
||||||
AppRoute route = match?.route ?? notFoundRoute;
|
AppRoute route = match?.route ?? notFoundRoute;
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, String> parameters = match?.parameters ?? <String, String>{};
|
Map<String, String> parameters = match?.parameters ?? <String, String>{};
|
||||||
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<Null> generator(RouteSettings routeSettings) {
|
||||||
|
return matchRoute(routeSettings.name, routeSettings: routeSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints the route tree so you can analyze it.
|
/// Prints the route tree so you can analyze it.
|
||||||
|
|
Loading…
Reference in New Issue