|
1 | | -import 'package:dataconnect/destination.dart'; |
2 | | -import 'package:dataconnect/login.dart'; |
3 | | -import 'package:dataconnect/profile.dart'; |
4 | | -import 'package:dataconnect/search.dart'; |
5 | 1 | import 'package:go_router/go_router.dart'; |
6 | 2 |
|
| 3 | +import 'login.dart'; |
| 4 | +import 'destination.dart'; |
| 5 | +import 'profile.dart'; |
| 6 | +import 'search.dart'; |
7 | 7 | import 'actor_detail.dart'; |
8 | 8 | import 'main.dart'; |
9 | 9 | import 'movie_detail.dart'; |
10 | 10 | import 'navigation_shell.dart'; |
11 | 11 | import 'sign_up.dart'; |
12 | 12 | import 'util/auth.dart'; |
13 | 13 |
|
14 | | -var router = GoRouter(initialLocation: homePath.path, routes: [ |
15 | | - StatefulShellRoute.indexedStack( |
| 14 | +var router = GoRouter( |
| 15 | + refreshListenable: Auth.instance, |
| 16 | + initialLocation: homePath.path, |
| 17 | + routes: [ |
| 18 | + StatefulShellRoute.indexedStack( |
16 | 19 | builder: (context, state, navigationShell) { |
17 | 20 | return NavigationShell(navigationShell: navigationShell); |
18 | 21 | }, |
19 | 22 | branches: [ |
20 | | - StatefulShellBranch(routes: [ |
21 | | - GoRoute( |
22 | | - path: homePath.path, |
23 | | - builder: (context, state) => const MyHomePage(), |
24 | | - ), |
25 | | - GoRoute( |
26 | | - path: '/movies/:movieId', |
27 | | - builder: (context, state) => |
28 | | - MovieDetail(id: state.pathParameters['movieId']!)), |
29 | | - GoRoute( |
30 | | - path: "/actors", |
31 | | - redirect: (context, state) => |
32 | | - '/actors/${state.pathParameters['actorId']}', |
33 | | - routes: [ |
34 | | - GoRoute( |
35 | | - path: ":actorId", |
36 | | - builder: (context, state) => |
37 | | - ActorDetail(actorId: state.pathParameters['actorId']!)) |
38 | | - ]) |
39 | | - ]), |
40 | | - StatefulShellBranch(routes: [ |
41 | | - GoRoute( |
42 | | - path: "/search", |
43 | | - builder: (context, state) => const Search(), |
44 | | - ), |
45 | | - ]), |
46 | | - StatefulShellBranch(routes: [ |
47 | | - GoRoute( |
48 | | - path: "/profile", |
| 23 | + StatefulShellBranch( |
| 24 | + routes: [ |
| 25 | + GoRoute( |
| 26 | + path: homePath.path, |
| 27 | + builder: (context, state) => const MyHomePage(), |
| 28 | + ), |
| 29 | + GoRoute( |
| 30 | + path: '/movies/:movieId', |
| 31 | + builder: (context, state) => |
| 32 | + MovieDetail(id: state.pathParameters['movieId']!)), |
| 33 | + GoRoute( |
| 34 | + path: "/actors", |
| 35 | + redirect: (context, state) => |
| 36 | + '/actors/${state.pathParameters['actorId']}', |
| 37 | + routes: [ |
| 38 | + GoRoute( |
| 39 | + path: ":actorId", |
| 40 | + builder: (context, state) => ActorDetail( |
| 41 | + actorId: state.pathParameters['actorId']!)) |
| 42 | + ]) |
| 43 | + ], |
| 44 | + ), |
| 45 | + StatefulShellBranch( |
| 46 | + routes: [ |
| 47 | + GoRoute( |
| 48 | + path: "/search", |
| 49 | + builder: (context, state) => const Search(), |
| 50 | + ), |
| 51 | + ], |
| 52 | + ), |
| 53 | + StatefulShellBranch( |
| 54 | + routes: [ |
| 55 | + GoRoute( |
| 56 | + path: "/profile", |
| 57 | + redirect: (context, state) async { |
| 58 | + return Auth.instance.isLoggedIn ? null : '/login'; |
| 59 | + }, |
| 60 | + builder: (context, state) => const Profile()), |
| 61 | + GoRoute( |
| 62 | + path: "/login", |
| 63 | + builder: (context, state) => const Login(), |
49 | 64 | redirect: (context, state) async { |
50 | | - return Auth.instance.isLoggedIn ? null : '/login'; |
| 65 | + return Auth.instance.isLoggedIn ? '/profile' : null; |
51 | 66 | }, |
52 | | - builder: (context, state) => const Profile()), |
53 | | - GoRoute( |
54 | | - path: "/login", |
55 | | - builder: (context, state) => const Login(), |
56 | | - redirect: (context, state) async { |
57 | | - return Auth.instance.isLoggedIn ? '/profile' : null; |
58 | | - }, |
59 | | - ), |
60 | | - GoRoute( |
61 | | - path: "/signup", |
62 | | - builder: (context, state) => const SignUp(), |
63 | | - ) |
64 | | - ]) |
65 | | - ]) |
66 | | -]); |
| 67 | + ), |
| 68 | + GoRoute( |
| 69 | + path: "/signup", |
| 70 | + builder: (context, state) => const SignUp(), |
| 71 | + ) |
| 72 | + ], |
| 73 | + ) |
| 74 | + ], |
| 75 | + ) |
| 76 | + ], |
| 77 | +); |
0 commit comments