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();
String initialLocation = HomeRoute.path;
String initialLocation = const HomeRoute().location;
if (initialLink case AsyncData(value: final link?)) {
initialLocation = AddProfileRoute(url: link.url).location;
}

View File

@@ -13,6 +13,7 @@ part 'desktop_routes.g.dart';
TypedGoRoute<HomeRoute>(
path: HomeRoute.path,
routes: [
TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path),
TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path),
TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.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 {
const AboutRoute();
static const path = '/about';

View File

@@ -13,9 +13,18 @@ part 'mobile_routes.g.dart';
TypedGoRoute<HomeRoute>(
path: HomeRoute.path,
routes: [
TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path),
TypedGoRoute<ProfilesRoute>(path: ProfilesRoute.path),
TypedGoRoute<NewProfileRoute>(path: NewProfileRoute.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),
@@ -30,10 +39,9 @@ class MobileWrapperRoute extends ShellRouteData {
}
}
@TypedGoRoute<LogsRoute>(path: LogsRoute.path)
class LogsRoute extends GoRouteData {
const LogsRoute();
static const path = '/logs';
static const path = 'logs';
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 {
const SettingsRoute();
static const path = '/settings';
static const path = 'settings';
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 {
const AboutRoute();
static const path = '/about';
static const path = 'about';
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;

View File

@@ -1,16 +1,14 @@
import 'package:go_router/go_router.dart';
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/shared_routes.dart' as shared;
import 'package:hiddify/utils/utils.dart';
export 'mobile_routes.dart';
export 'shared_routes.dart' hide $appRoutes;
export 'shared_routes.dart';
List<RouteBase> get $routes => [
if (PlatformUtils.isDesktop)
...desktop.$appRoutes
else
...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/profiles/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';
part 'shared_routes.g.dart';
List<RouteBase> get $sharedRoutes => $appRoutes;
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
class HomeRoute extends GoRouteData {
@@ -33,10 +28,9 @@ class ProxiesRoute extends GoRouteData {
}
}
@TypedGoRoute<AddProfileRoute>(path: AddProfileRoute.path)
class AddProfileRoute extends GoRouteData {
const AddProfileRoute({this.url});
static const path = '/add';
static const path = 'add';
final String? url;
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(),
);
}
}