2023-02-06 23:45:56 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:momo/material/home.dart';
|
2023-02-07 17:28:01 +08:00
|
|
|
import 'package:momo/material/login.dart';
|
2023-02-06 23:45:56 +08:00
|
|
|
|
|
|
|
class MyMaterialRouterConfig {
|
2023-02-07 17:28:01 +08:00
|
|
|
late GoRouter router;
|
|
|
|
|
|
|
|
MyMaterialRouterConfig(String? token) {
|
|
|
|
router = GoRouter(
|
|
|
|
routes: <RouteBase>[
|
|
|
|
GoRoute(
|
|
|
|
path: '/',
|
|
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
|
|
return const HomePage();
|
|
|
|
},
|
|
|
|
redirect: (BuildContext context, GoRouterState state) {
|
|
|
|
if (token == null || token.isEmpty) {
|
|
|
|
return '/login';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
GoRoute(
|
|
|
|
path: "/login",
|
|
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
|
|
return const LoginPage();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2023-02-06 23:45:56 +08:00
|
|
|
}
|