GetMiddleware
class RMRouteMiddleWare extends GetMiddleware {
@override
RouteSettings redirect(String route) {
/// 可以在这里进行跳转前的逻辑处理
return RouteSettings(name: '/login');
}
}
void main() {
runApp(GetMaterialApp(
initialRoute: '/home',
getPages: [
GetPage(name: '/home', page: () => HomePage()),
GetPage(name: '/login', page: () => LoginView()),
GetPage(
name: '/other',
page: () => OtherPage(),
middlewares: [RMRouteMiddleWare()]),/// 中间件
],
));
}