handler只是单个路由的配置,这节课咱们要学习路由的总体配置app
新建routers.dart文件来作总体配置学习
detailsHandler就是咱们在router_handler里面定义的detailsHandlerui
当路由不存在的时候,给用户一个反馈。router.notFoundHandlerspa
这样咱们的整理路由就写完了。code
为了方便使用还要作一件事,作一个静态文件,把它静态化之后直接调用,不用再New 去调用了。router
routers/application.dart。在routers下面新建了application.dart文件blog
静态化Router,这样咱们在使用的时候就能够直接用 Application.Router就能够了。路由
routers/routers.dartio
import 'package:flutter/material.dart'; import 'package:fluro/fluro.dart'; import './router_handler.dart'; class Routes { static String root='/';//配置根目录 static String detailsPage='/detail';//详情页面 static void configurreRoutes(Router router){ //找不到路由的状况 router.notFoundHandler = new Handler( handlerFunc: (BuildContext context,Map<String,List<String>> params){ print('ERROR====>ROUTES WAS NOT FOUND!!!!!!'); } ); //总体配置 router.define(detailsPage,handler:detailsHandler); } }
routers/application.dartclass
import 'package:fluro/fluro.dart'; class Application { static Router router; }