go method

MaterialPageRoute go({
  1. String route = "/",
  2. required WidgetBuilder errorRoute,
  3. Map<String, dynamic>? initParams,
})

路由跳转(一般配合onGenerateRoute一起使用) 通过此方式跳转的对应页面以NavigatorManager.getRouteParams方式获取 route路由及参数地址,通过CSRouterUrlParse解析后查找CSRouter.pageRoutes()再跳转; errorRoute在route解析失败或未搭到对应的路由时渲染当前页面 initParams初始化参数

Implementation

MaterialPageRoute go(
    {String route = "/",
    required WidgetBuilder errorRoute,
    Map<String, dynamic>? initParams}) {
  WidgetBuilder builder;
  String _routeName;
  if (initParams == null) {
    initParams = {};
  }
  if (route == "/") {
    _routeName = "/";
    builder = errorRoute;
  } else {
    var parse = RouteUriParse(route);
    Map<String, String> parameter = parse.queryParameters;
    _routeName = parse.withoutQueryPath;
    initParams.addAll(parameter);
    if (_routeName.isEmptyString) {
      _routeName = "/";
      //在不符合定义规则的情况下,parse.withoutQueryPath可能为空
      builder = errorRoute;
    } else {
      builder = RouteUtils.instance.getWidget(_routeName) ?? errorRoute;
    }
  }
  var pageRoute = MaterialPageRoute(
      builder: builder,
      settings: RouteSettings(name: _routeName, arguments: initParams));
  return pageRoute;
}