refactor: enhance child route management in ClientPaths and StaffPaths; ensure proper handling of empty child paths
This commit is contained in:
@@ -48,7 +48,7 @@ extension ClientNavigator on IModularNavigator {
|
||||
/// This is typically called after successful authentication or when
|
||||
/// returning to the main application from a deep feature.
|
||||
///
|
||||
/// Uses absolute navigation to ensure proper routing from any context.
|
||||
/// Uses pushNamed to avoid trailing slash issues with navigate().
|
||||
void toClientHome() {
|
||||
navigate(ClientPaths.home);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,21 @@ class ClientPaths {
|
||||
/// Generate child route based on the given route and parent route
|
||||
///
|
||||
/// This is useful for creating nested routes within modules.
|
||||
static String childRoute(String parent, String child) => child.replaceFirst(parent, '');
|
||||
static String childRoute(String parent, String child) {
|
||||
final String childPath = child.replaceFirst(parent, '');
|
||||
|
||||
// check if the child path is empty
|
||||
if (childPath.isEmpty) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
// ensure the child path starts with a '/'
|
||||
if (!childPath.startsWith('/')) {
|
||||
return '/$childPath';
|
||||
}
|
||||
|
||||
return childPath;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// AUTHENTICATION
|
||||
|
||||
@@ -16,8 +16,22 @@ class StaffPaths {
|
||||
/// Generate child route based on the given route and parent route
|
||||
///
|
||||
/// This is useful for creating nested routes within modules.
|
||||
static String childRoute(String parent, String child) => child.replaceFirst(parent, '');
|
||||
static String childRoute(String parent, String child) {
|
||||
final String childPath = child.replaceFirst(parent, '');
|
||||
|
||||
// check if the child path is empty
|
||||
if (childPath.isEmpty) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
// ensure the child path starts with a '/'
|
||||
if (!childPath.startsWith('/')) {
|
||||
return '/$childPath';
|
||||
}
|
||||
|
||||
return childPath;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// AUTHENTICATION
|
||||
// ==========================================================================
|
||||
@@ -93,7 +107,8 @@ class StaffPaths {
|
||||
/// Personal information onboarding.
|
||||
///
|
||||
/// Collect basic personal information during staff onboarding.
|
||||
static const String onboardingPersonalInfo = '/worker-main/onboarding/personal-info';
|
||||
static const String onboardingPersonalInfo =
|
||||
'/worker-main/onboarding/personal-info';
|
||||
|
||||
/// Emergency contact information.
|
||||
///
|
||||
|
||||
@@ -37,7 +37,7 @@ class ClientSignInPage extends StatelessWidget {
|
||||
final TranslationsClientAuthenticationSignInPageEn i18n = t.client_authentication.sign_in_page;
|
||||
final ClientAuthBloc authBloc = Modular.get<ClientAuthBloc>();
|
||||
|
||||
return BlocProvider.value(
|
||||
return BlocProvider<ClientAuthBloc>.value(
|
||||
value: authBloc,
|
||||
child: BlocConsumer<ClientAuthBloc, ClientAuthState>(
|
||||
listener: (BuildContext context, ClientAuthState state) {
|
||||
|
||||
@@ -47,6 +47,9 @@ class ClientHomeModule extends Module {
|
||||
|
||||
@override
|
||||
void routes(RouteManager r) {
|
||||
r.child(ClientPaths.childRoute(ClientPaths.home, ClientPaths.home), child: (_) => const ClientHomePage());
|
||||
r.child(
|
||||
ClientPaths.childRoute(ClientPaths.home, ClientPaths.home),
|
||||
child: (_) => const ClientHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user