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