refactor: enhance child route management in ClientPaths and StaffPaths; ensure proper handling of empty child paths

This commit is contained in:
Achintha Isuru
2026-02-04 17:58:37 -05:00
parent fa6fa90bb8
commit b5c3af580c
6 changed files with 53 additions and 20 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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.
///

View File

@@ -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) {

View File

@@ -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(),
);
}
}