fix
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:momo/material/gallery.dart';
|
||||
import 'package:momo/material/home.dart';
|
||||
import 'package:momo/material/login.dart';
|
||||
import 'package:momo/material/profile.dart';
|
||||
|
||||
class MyMaterialRouterConfig {
|
||||
late GoRouter router;
|
||||
@ -9,23 +11,65 @@ class MyMaterialRouterConfig {
|
||||
MyMaterialRouterConfig(String? token) {
|
||||
router = GoRouter(
|
||||
routes: <RouteBase>[
|
||||
ShellRoute(
|
||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
return HomePage(
|
||||
content: child,
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "/",
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
const NoTransitionPage(child: Gallery()),
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
if (token == null || token.isEmpty) {
|
||||
return '/login';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
GoRoute(
|
||||
path: "/profile",
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
const NoTransitionPage(child: Profile())),
|
||||
GoRoute(
|
||||
path: "/detail",
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
const NoTransitionPage(
|
||||
child: Center(
|
||||
child: Text("detail"),
|
||||
)))
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
path: "/login",
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const HomePage();
|
||||
return const LoginPage();
|
||||
},
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
if (token == null || token.isEmpty) {
|
||||
return '/login';
|
||||
if (token != null && token.isNotEmpty) {
|
||||
return '/';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
GoRoute(
|
||||
path: "/login",
|
||||
builder: (BuildContext context, GoRouterState state) {
|
||||
return const LoginPage();
|
||||
},
|
||||
)
|
||||
// ShellRoute(
|
||||
// builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text("nest"),
|
||||
// ),
|
||||
// body: child,
|
||||
// );
|
||||
// },
|
||||
// routes: [
|
||||
// GoRoute(
|
||||
// path: '/',
|
||||
// builder: (BuildContext context, GoRouterState state) {
|
||||
// return Center(
|
||||
// child: Text("login"),
|
||||
// );
|
||||
// })
|
||||
// ]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user