go method
MaterialPageRoute
go({
- String route = "/",
- required WidgetBuilder errorRoute,
- 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;
}