MOBILE-3609 settings: Fix about routes
This commit is contained in:
		
							parent
							
								
									87aa244ad7
								
							
						
					
					
						commit
						ae76e3da02
					
				@ -40,10 +40,11 @@ function buildAppRoutes(injector: Injector): Routes {
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Create a url matcher that will only match when a given condition is met.
 | 
					 * Create a url matcher that will only match when a given condition is met.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 | 
					 * @param pathOrMatcher Original path or matcher configured in the route.
 | 
				
			||||||
 * @param condition Condition.
 | 
					 * @param condition Condition.
 | 
				
			||||||
 * @return Conditional url matcher.
 | 
					 * @return Conditional url matcher.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function buildConditionalUrlMatcher(condition: () => boolean): UrlMatcher {
 | 
					function buildConditionalUrlMatcher(pathOrMatcher: string | UrlMatcher, condition: () => boolean): UrlMatcher {
 | 
				
			||||||
    // Create a matcher based on Angular's default matcher.
 | 
					    // Create a matcher based on Angular's default matcher.
 | 
				
			||||||
    // see https://github.com/angular/angular/blob/10.0.x/packages/router/src/shared.ts#L127
 | 
					    // see https://github.com/angular/angular/blob/10.0.x/packages/router/src/shared.ts#L127
 | 
				
			||||||
    return (segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null => {
 | 
					    return (segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null => {
 | 
				
			||||||
@ -52,10 +53,20 @@ function buildConditionalUrlMatcher(condition: () => boolean): UrlMatcher {
 | 
				
			|||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const { path, pathMatch } = route as { path: string; pathMatch?: 'full' };
 | 
					        // Use existing matcher if any.
 | 
				
			||||||
        const posParams: Record<string, UrlSegment> = {};
 | 
					        if (typeof pathOrMatcher === 'function') {
 | 
				
			||||||
        const isFullMatch = pathMatch === 'full';
 | 
					            return pathOrMatcher(segments, segmentGroup, route);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const path = pathOrMatcher;
 | 
				
			||||||
        const parts = path.split('/');
 | 
					        const parts = path.split('/');
 | 
				
			||||||
 | 
					        const isFullMatch = route.pathMatch === 'full';
 | 
				
			||||||
 | 
					        const posParams: Record<string, UrlSegment> = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // The path matches anything.
 | 
				
			||||||
 | 
					        if (path === '') {
 | 
				
			||||||
 | 
					            return (!isFullMatch || segments.length === 0) ? { consumed: [] } : null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // The actual URL is shorter than the config, no match.
 | 
					        // The actual URL is shorter than the config, no match.
 | 
				
			||||||
        if (parts.length > segments.length) {
 | 
					        if (parts.length > segments.length) {
 | 
				
			||||||
@ -97,12 +108,15 @@ export type ModuleRoutesConfig = Routes | Partial<ModuleRoutes>;
 | 
				
			|||||||
 * @return Conditional routes.
 | 
					 * @return Conditional routes.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export function conditionalRoutes(routes: Routes, condition: () => boolean): Routes {
 | 
					export function conditionalRoutes(routes: Routes, condition: () => boolean): Routes {
 | 
				
			||||||
    const conditionalMatcher = buildConditionalUrlMatcher(condition);
 | 
					    return routes.map(route => {
 | 
				
			||||||
 | 
					        // We need to remove the path from the route because Angular doesn't call the matcher for empty paths.
 | 
				
			||||||
 | 
					        const { path, matcher, ...newRoute } = route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return routes.map(route => ({
 | 
					        return {
 | 
				
			||||||
        ...route,
 | 
					            ...newRoute,
 | 
				
			||||||
        matcher: conditionalMatcher,
 | 
					            matcher: buildConditionalUrlMatcher(matcher || path!, condition),
 | 
				
			||||||
    }));
 | 
					        };
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 | 
				
			|||||||
@ -26,18 +26,6 @@ const routes: Routes = [
 | 
				
			|||||||
        path: '',
 | 
					        path: '',
 | 
				
			||||||
        component: CoreSettingsAboutPage,
 | 
					        component: CoreSettingsAboutPage,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        path: 'deviceinfo',
 | 
					 | 
				
			||||||
        loadChildren: () =>
 | 
					 | 
				
			||||||
            import('@features/settings/pages/deviceinfo/deviceinfo.module')
 | 
					 | 
				
			||||||
                .then(m => m.CoreSettingsDeviceInfoPageModule),
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        path: 'licenses',
 | 
					 | 
				
			||||||
        loadChildren: () =>
 | 
					 | 
				
			||||||
            import('@features/settings/pages/licenses/licenses.module')
 | 
					 | 
				
			||||||
                .then(m => m.CoreSettingsLicensesPageModule),
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@NgModule({
 | 
					@NgModule({
 | 
				
			||||||
 | 
				
			|||||||
@ -46,24 +46,40 @@ const sectionRoutes: Routes = [
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const routes: Routes = [
 | 
					const mobileRoutes: Routes = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        matcher: segments => {
 | 
					        path: '',
 | 
				
			||||||
            const matches = CoreScreen.instance.isMobile ? segments.length === 0 : true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return matches ? { consumed: [] } : null;
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        component: CoreSettingsIndexPage,
 | 
					        component: CoreSettingsIndexPage,
 | 
				
			||||||
        children: conditionalRoutes([
 | 
					    },
 | 
				
			||||||
 | 
					    ...sectionRoutes,
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const tabletRoutes: Routes = [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        path: '',
 | 
				
			||||||
 | 
					        component: CoreSettingsIndexPage,
 | 
				
			||||||
 | 
					        children: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                path: '',
 | 
					                path: '',
 | 
				
			||||||
                pathMatch: 'full',
 | 
					                pathMatch: 'full',
 | 
				
			||||||
                redirectTo: 'general',
 | 
					                redirectTo: 'general',
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            ...sectionRoutes,
 | 
					            ...sectionRoutes,
 | 
				
			||||||
        ], () => !CoreScreen.instance.isMobile),
 | 
					        ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const routes: Routes = [
 | 
				
			||||||
 | 
					    ...conditionalRoutes(mobileRoutes, () => CoreScreen.instance.isMobile),
 | 
				
			||||||
 | 
					    ...conditionalRoutes(tabletRoutes, () => CoreScreen.instance.isTablet),
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        path: 'about/deviceinfo',
 | 
				
			||||||
 | 
					        loadChildren: () => import('./pages/deviceinfo/deviceinfo.module').then(m => m.CoreSettingsDeviceInfoPageModule),
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        path: 'about/licenses',
 | 
				
			||||||
 | 
					        loadChildren: () => import('./pages/licenses/licenses.module').then(m => m.CoreSettingsLicensesPageModule),
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    ...conditionalRoutes(sectionRoutes, () => CoreScreen.instance.isMobile),
 | 
					 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@NgModule({
 | 
					@NgModule({
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user