0.引入
fluro: "^1.4.0"
1.定义路由final
router = FluroRouter();
放到全局变量中去
class Application{
static FluroRouter router;
}
在程序最开始的main()入口程序的build中声明注册
final router = FluroRouter();
Routes.configureRoutes(router);
Application.router = router;
然后,在对应的MaterialApp中添加一段代码
onGenerateRoute: Application.router.generator,
其中的Routes.configureRoutes(router);见第三步定义的。
2.定义一个路由规则
Handler commandHandler = Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params){
String id = params['id'][0];
print('index>details goodsID is ${id}');
return MyApp(id);
}
);
3.自定义路由配置
class Routes{
static String root='/test/';
static String commandPage = 'command'; //路由路径
static void configureRoutes(FluroRouter router){
router.notFoundHandler= new Handler(
handlerFunc: (BuildContext context,Map<String,List<String>> params){
print('ERROR====>ROUTE WAS NOT FONUND!!!');
}
);
//每一个路由规则都需要在这里进行新的定义
router.define(root + commandPage, commandHandler);
}
4.使用
在需要使用路由的地方,比如说跳转
Application.router.navigateTo(context,"/command?id=234}");
其中id是在路由规则commandHandler中声明的参数key;/command是在Routes中声明的路由路径。
“打完收工!”