on static method

void on(
  1. String path,
  2. dynamic action, {
  3. RouteActivation? canActivated,
})

This function is used to register your application in Karee Router module.

path is the string that represents the resource location.

action is the action to perform when resource represented by path is needed.

canActivated is the route guard, use to allow the request to access to the desired resource.

Implementation

static void on(String path, dynamic action, {RouteActivation? canActivated}) {
  assert(action != null && action.toString().isNotEmpty);
  assert(path.isNotEmpty);

  final canActivateRoute = canActivated ?? defaultRouteActivation;

  var routeEntry = _RouteEntry(path, action, canActivateRoute);

  if (path.contains(_pathVariableRegExp)) {
    var meta = _ParameterizedRoute(routeEntry, []);
    var newPath = path.replaceAllMapped(_pathVariableRegExp, (m) {
      meta.parameters.add(path.substring(m.start + 1, m.end - 1));
      return _pathVariableGroup;
    });
    _routeWithParams[newPath] = meta;
  } else {
    _routeMap[path] = routeEntry;
  }
  // routeMap[route] = action;
  if (canActivateRoute != defaultRouteActivation) {
    var routes = _routeActivationMap[canActivateRoute] ?? <String>[];
    routes.add(path);
    _routeActivationMap[canActivateRoute] = routes;
  }
}