diff --git a/src/core/features/courses/courses-lazy.module.ts b/src/core/features/courses/courses-lazy.module.ts index cfffc2db4..595dbc641 100644 --- a/src/core/features/courses/courses-lazy.module.ts +++ b/src/core/features/courses/courses-lazy.module.ts @@ -12,35 +12,53 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; +import { Injector, NgModule } from '@angular/core'; +import { RouterModule, ROUTES, Routes } from '@angular/router'; +import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; +import { CoreCoursesMyCoursesMainMenuHandlerService } from './services/handlers/my-courses-mainmenu'; -const routes: Routes = [ - { - path: '', - redirectTo: 'list', - pathMatch: 'full', - }, - { - path: 'categories', - redirectTo: 'categories/root', // Fake "id". - pathMatch: 'full', - }, - { - path: 'categories/:id', - loadChildren: () => - import('./pages/categories/categories.module') - .then(m => m.CoreCoursesCategoriesPageModule), - }, - { - path: 'list', - loadChildren: () => - import('./pages/list/list.module') - .then(m => m.CoreCoursesListPageModule), - }, -]; +function buildRoutes(injector: Injector): Routes { + return [ + { + path: 'my', + data: { + mainMenuTabRoot: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME, + }, + loadChildren: () => import('./pages/my/my.module').then(m => m.CoreCoursesMyCoursesPageModule), + }, + { + path: 'categories', + redirectTo: 'categories/root', // Fake "id". + pathMatch: 'full', + }, + { + path: 'categories/:id', + loadChildren: () => + import('./pages/categories/categories.module') + .then(m => m.CoreCoursesCategoriesPageModule), + }, + { + path: 'list', + loadChildren: () => + import('./pages/list/list.module') + .then(m => m.CoreCoursesListPageModule), + }, + ...buildTabMainRoutes(injector, { + redirectTo: 'my', + pathMatch: 'full', + }), + ]; +} @NgModule({ - imports: [RouterModule.forChild(routes)], + exports: [RouterModule], + providers: [ + { + provide: ROUTES, + multi: true, + deps: [Injector], + useFactory: buildRoutes, + }, + ], }) export class CoreCoursesLazyModule {} diff --git a/src/core/features/courses/courses.module.ts b/src/core/features/courses/courses.module.ts index f4f801622..3423b63b2 100644 --- a/src/core/features/courses/courses.module.ts +++ b/src/core/features/courses/courses.module.ts @@ -50,17 +50,10 @@ const mainMenuHomeChildrenRoutes: Routes = [ }, ]; -const mainMenuHomeSiblingRoutes: Routes = [ - { - path: 'courses', - loadChildren: () => import('./courses-lazy.module').then(m => m.CoreCoursesLazyModule), - }, -]; - -const mainMenuTabRoutes: Routes = [ +const routes: Routes = [ { path: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME, - loadChildren: () => import('./pages/my/my.module').then(m => m.CoreCoursesMyCoursesPageModule), + loadChildren: () => import('./courses-lazy.module').then(m => m.CoreCoursesLazyModule), }, ]; @@ -68,10 +61,9 @@ const mainMenuTabRoutes: Routes = [ imports: [ CoreMainMenuHomeRoutingModule.forChild({ children: mainMenuHomeChildrenRoutes, - siblings: mainMenuHomeSiblingRoutes, }), - CoreMainMenuRoutingModule.forChild({ children: mainMenuTabRoutes }), - CoreMainMenuTabRoutingModule.forChild(mainMenuTabRoutes), + CoreMainMenuRoutingModule.forChild({ children: routes }), + CoreMainMenuTabRoutingModule.forChild(routes), ], exports: [CoreMainMenuRoutingModule], providers: [ diff --git a/src/core/features/courses/pages/my/my.module.ts b/src/core/features/courses/pages/my/my.module.ts index c6ed5b0b3..96b405151 100644 --- a/src/core/features/courses/pages/my/my.module.ts +++ b/src/core/features/courses/pages/my/my.module.ts @@ -12,53 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Injector, NgModule } from '@angular/core'; -import { RouterModule, ROUTES, Routes } from '@angular/router'; +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; import { CoreSharedModule } from '@/core/shared.module'; import { CoreBlockComponentsModule } from '@features/block/components/components.module'; import { CoreCoursesMyCoursesPage } from './my'; import { CoreMainMenuComponentsModule } from '@features/mainmenu/components/components.module'; -import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; -import { CoreCoursesMyCoursesMainMenuHandlerService } from '@features/courses/services/handlers/my-courses-mainmenu'; -function buildRoutes(injector: Injector): Routes { - return [ - { - path: '', - component: CoreCoursesMyCoursesPage, - data: { - mainMenuTabRoot: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME, - }, - }, - { - path: 'list', - loadChildren: () => - import('../list/list.module') - .then(m => m.CoreCoursesListPageModule), - }, - ...buildTabMainRoutes(injector, { - redirectTo: '', - pathMatch: 'full', - }), - ]; -} +const routes: Routes = [ + { + path: '', + component: CoreCoursesMyCoursesPage, + }, +]; @NgModule({ imports: [ + RouterModule.forChild(routes), CoreSharedModule, CoreBlockComponentsModule, CoreMainMenuComponentsModule, ], - providers: [ - { - provide: ROUTES, - multi: true, - deps: [Injector], - useFactory: buildRoutes, - }, - ], declarations: [ CoreCoursesMyCoursesPage, ], diff --git a/src/core/features/courses/services/handlers/my-courses-mainmenu.ts b/src/core/features/courses/services/handlers/my-courses-mainmenu.ts index b800900f8..619327dc7 100644 --- a/src/core/features/courses/services/handlers/my-courses-mainmenu.ts +++ b/src/core/features/courses/services/handlers/my-courses-mainmenu.ts @@ -27,7 +27,7 @@ import { CoreDashboardHomeHandler } from './dashboard-home'; @Injectable({ providedIn: 'root' }) export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuHandler { - static readonly PAGE_NAME = 'my'; + static readonly PAGE_NAME = 'courses'; name = 'CoreCoursesMyCourses'; priority = 900;