Fix routing

This commit is contained in:
problematicconsumer
2023-07-28 00:03:01 +03:30
parent 2bfd954946
commit 14369d0a03
5 changed files with 44 additions and 35 deletions

View File

@@ -18,7 +18,7 @@ GoRouter router(RouterRef ref) {
}, },
); );
final initialLink = deepLink.read(); final initialLink = deepLink.read();
String initialLocation = HomeRoute.path; String initialLocation = const HomeRoute().location;
if (initialLink case AsyncData(value: final link?)) { if (initialLink case AsyncData(value: final link?)) {
initialLocation = AddProfileRoute(url: link.url).location; initialLocation = AddProfileRoute(url: link.url).location;
} }

View File

@@ -13,6 +13,7 @@ part 'desktop_routes.g.dart';
TypedGoRoute<HomeRoute>( TypedGoRoute<HomeRoute>(
path: HomeRoute.path, path: HomeRoute.path,
routes: [ routes: [
TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path),
TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path), TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path),
TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.path), TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.path),
TypedGoRoute<ProfileDetailsRoute>(path: ProfileDetailsRoute.path), TypedGoRoute<ProfileDetailsRoute>(path: ProfileDetailsRoute.path),
@@ -58,6 +59,19 @@ class SettingsRoute extends GoRouteData {
} }
} }
class ClashOverridesRoute extends GoRouteData {
const ClashOverridesRoute();
static const path = 'clash';
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const MaterialPage(
fullscreenDialog: true,
child: ClashOverridesPage(),
);
}
}
class AboutRoute extends GoRouteData { class AboutRoute extends GoRouteData {
const AboutRoute(); const AboutRoute();
static const path = '/about'; static const path = '/about';

View File

@@ -13,9 +13,18 @@ part 'mobile_routes.g.dart';
TypedGoRoute<HomeRoute>( TypedGoRoute<HomeRoute>(
path: HomeRoute.path, path: HomeRoute.path,
routes: [ routes: [
TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path),
TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path), TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path),
TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.path), TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.path),
TypedGoRoute<ProfileDetailsRoute>(path: ProfileDetailsRoute.path), TypedGoRoute<ProfileDetailsRoute>(path: ProfileDetailsRoute.path),
TypedGoRoute<LogsRoute>(path: LogsRoute.path),
TypedGoRoute<SettingsRoute>(
path: SettingsRoute.path,
routes: [
TypedGoRoute<ClashOverridesRoute>(path: ClashOverridesRoute.path),
],
),
TypedGoRoute<AboutRoute>(path: AboutRoute.path),
], ],
), ),
TypedGoRoute<ProxiesRoute>(path: ProxiesRoute.path), TypedGoRoute<ProxiesRoute>(path: ProxiesRoute.path),
@@ -30,10 +39,9 @@ class MobileWrapperRoute extends ShellRouteData {
} }
} }
@TypedGoRoute<LogsRoute>(path: LogsRoute.path)
class LogsRoute extends GoRouteData { class LogsRoute extends GoRouteData {
const LogsRoute(); const LogsRoute();
static const path = '/logs'; static const path = 'logs';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey; static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
@@ -46,15 +54,9 @@ class LogsRoute extends GoRouteData {
} }
} }
@TypedGoRoute<SettingsRoute>(
path: SettingsRoute.path,
routes: [
TypedGoRoute<ClashOverridesRoute>(path: ClashOverridesRoute.path),
],
)
class SettingsRoute extends GoRouteData { class SettingsRoute extends GoRouteData {
const SettingsRoute(); const SettingsRoute();
static const path = '/settings'; static const path = 'settings';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey; static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
@@ -67,10 +69,24 @@ class SettingsRoute extends GoRouteData {
} }
} }
@TypedGoRoute<AboutRoute>(path: AboutRoute.path) class ClashOverridesRoute extends GoRouteData {
const ClashOverridesRoute();
static const path = 'clash';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const MaterialPage(
fullscreenDialog: true,
child: ClashOverridesPage(),
);
}
}
class AboutRoute extends GoRouteData { class AboutRoute extends GoRouteData {
const AboutRoute(); const AboutRoute();
static const path = '/about'; static const path = 'about';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey; static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;

View File

@@ -1,16 +1,14 @@
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hiddify/core/router/routes/desktop_routes.dart' as desktop; import 'package:hiddify/core/router/routes/desktop_routes.dart' as desktop;
import 'package:hiddify/core/router/routes/mobile_routes.dart' as mobile; import 'package:hiddify/core/router/routes/mobile_routes.dart' as mobile;
import 'package:hiddify/core/router/routes/shared_routes.dart' as shared;
import 'package:hiddify/utils/utils.dart'; import 'package:hiddify/utils/utils.dart';
export 'mobile_routes.dart'; export 'mobile_routes.dart';
export 'shared_routes.dart' hide $appRoutes; export 'shared_routes.dart';
List<RouteBase> get $routes => [ List<RouteBase> get $routes => [
if (PlatformUtils.isDesktop) if (PlatformUtils.isDesktop)
...desktop.$appRoutes ...desktop.$appRoutes
else else
...mobile.$appRoutes, ...mobile.$appRoutes,
...shared.$appRoutes,
]; ];

View File

@@ -4,13 +4,8 @@ import 'package:hiddify/features/home/view/view.dart';
import 'package:hiddify/features/profile_detail/view/view.dart'; import 'package:hiddify/features/profile_detail/view/view.dart';
import 'package:hiddify/features/profiles/view/view.dart'; import 'package:hiddify/features/profiles/view/view.dart';
import 'package:hiddify/features/proxies/view/view.dart'; import 'package:hiddify/features/proxies/view/view.dart';
import 'package:hiddify/features/settings/view/view.dart';
import 'package:hiddify/utils/utils.dart'; import 'package:hiddify/utils/utils.dart';
part 'shared_routes.g.dart';
List<RouteBase> get $sharedRoutes => $appRoutes;
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
class HomeRoute extends GoRouteData { class HomeRoute extends GoRouteData {
@@ -33,10 +28,9 @@ class ProxiesRoute extends GoRouteData {
} }
} }
@TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path)
class AddProfileRoute extends GoRouteData { class AddProfileRoute extends GoRouteData {
const AddProfileRoute({this.url}); const AddProfileRoute({this.url});
static const path = '/add'; static const path = 'add';
final String? url; final String? url;
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey; static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
@@ -103,16 +97,3 @@ class ProfileDetailsRoute extends GoRouteData {
); );
} }
} }
class ClashOverridesRoute extends GoRouteData {
const ClashOverridesRoute();
static const path = 'clash-overrides';
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const MaterialPage(
fullscreenDialog: true,
child: ClashOverridesPage(),
);
}
}