diff --git a/src/addons/privatefiles/privatefiles-lazy.module.ts b/src/addons/privatefiles/privatefiles-lazy.module.ts index 307142373..405d9ff9d 100644 --- a/src/addons/privatefiles/privatefiles-lazy.module.ts +++ b/src/addons/privatefiles/privatefiles-lazy.module.ts @@ -12,23 +12,33 @@ // 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'; -const routes: Routes = [ - { - path: '', - redirectTo: 'root', // Fake "hash". - pathMatch: 'full', - }, - { - path: ':hash', - loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule), - }, -]; +import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; + +function buildRoutes(injector: Injector): Routes { + return [ + { + path: ':hash', + loadChildren: () => import('./pages/index/index.module').then(m => m.AddonPrivateFilesIndexPageModule), + }, + ...buildTabMainRoutes(injector, { + redirectTo: 'root', // Fake "hash". + pathMatch: 'full', + }), + ]; +} @NgModule({ - imports: [RouterModule.forChild(routes)], exports: [RouterModule], + providers: [ + { + provide: ROUTES, + multi: true, + deps: [Injector], + useFactory: buildRoutes, + }, + ], }) export class AddonPrivateFilesLazyModule {} diff --git a/src/core/features/mainmenu/mainmenu-tab-routing.module.ts b/src/core/features/mainmenu/mainmenu-tab-routing.module.ts new file mode 100644 index 000000000..d673d2a34 --- /dev/null +++ b/src/core/features/mainmenu/mainmenu-tab-routing.module.ts @@ -0,0 +1,47 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { InjectionToken, Injector, ModuleWithProviders, NgModule } from '@angular/core'; +import { Route, Routes } from '@angular/router'; + +import { ModuleRoutes, resolveModuleRoutes } from '@/app/app-routing.module'; + +export const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES'); + +export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes { + const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES); + + mainRoute.path = mainRoute.path || ''; + mainRoute.children = mainRoute.children || []; + mainRoute.children.concat(routes.children); + + return [ + mainRoute, + ...routes.siblings, + ]; +} + +@NgModule() +export class CoreMainMenuTabRoutingModule { + + static forChild(routes: Partial): ModuleWithProviders { + return { + ngModule: CoreMainMenuTabRoutingModule, + providers: [ + { provide: MAIN_MENU_TAB_ROUTES, multi: true, useValue: routes }, + ], + }; + } + +} diff --git a/src/core/features/mainmenu/pages/home/home.module.ts b/src/core/features/mainmenu/pages/home/home.module.ts index 674de5397..c61770912 100644 --- a/src/core/features/mainmenu/pages/home/home.module.ts +++ b/src/core/features/mainmenu/pages/home/home.module.ts @@ -24,16 +24,17 @@ import { CoreDirectivesModule } from '@directives/directives.module'; import { CoreMainMenuHomePage } from './home'; import { MAIN_MENU_HOME_ROUTES } from './home-routing.module'; +import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; function buildRoutes(injector: Injector): Routes { const routes = resolveModuleRoutes(injector, MAIN_MENU_HOME_ROUTES); return [ - { + ...buildTabMainRoutes(injector, { path: '', component: CoreMainMenuHomePage, children: routes.children, - }, + }), ...routes.siblings, ]; } diff --git a/src/core/features/mainmenu/pages/more/more-routing.module.ts b/src/core/features/mainmenu/pages/more/more-routing.module.ts deleted file mode 100644 index 11ed18c24..000000000 --- a/src/core/features/mainmenu/pages/more/more-routing.module.ts +++ /dev/null @@ -1,33 +0,0 @@ -// (C) Copyright 2015 Moodle Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; - -import { ModuleRoutes } from '@/app/app-routing.module'; - -export const MAIN_MENU_MORE_ROUTES = new InjectionToken('MAIN_MENU_MORE_ROUTES'); - -@NgModule() -export class CoreMainMenuMoreRoutingModule { - - static forChild(routes: Partial): ModuleWithProviders { - return { - ngModule: CoreMainMenuMoreRoutingModule, - providers: [ - { provide: MAIN_MENU_MORE_ROUTES, multi: true, useValue: routes }, - ], - }; - } - -} diff --git a/src/core/features/mainmenu/pages/more/more.module.ts b/src/core/features/mainmenu/pages/more/more.module.ts index b3e48f897..0893e966c 100644 --- a/src/core/features/mainmenu/pages/more/more.module.ts +++ b/src/core/features/mainmenu/pages/more/more.module.ts @@ -14,29 +14,14 @@ import { Injector, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { RouterModule, ROUTES, Routes } from '@angular/router'; +import { RouterModule, ROUTES } from '@angular/router'; import { IonicModule } from '@ionic/angular'; import { TranslateModule } from '@ngx-translate/core'; -import { resolveModuleRoutes } from '@/app/app-routing.module'; import { CoreComponentsModule } from '@components/components.module'; import { CoreDirectivesModule } from '@directives/directives.module'; - import { CoreMainMenuMorePage } from './more'; -import { MAIN_MENU_MORE_ROUTES } from './more-routing.module'; - -function buildRoutes(injector: Injector): Routes { - const routes = resolveModuleRoutes(injector, MAIN_MENU_MORE_ROUTES); - - return [ - { - path: '', - component: CoreMainMenuMorePage, - children: routes.children, - }, - ...routes.siblings, - ]; -} +import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; @NgModule({ imports: [ @@ -47,7 +32,14 @@ function buildRoutes(injector: Injector): Routes { CoreDirectivesModule, ], providers: [ - { provide: ROUTES, multi: true, useFactory: buildRoutes, deps: [Injector] }, + { + provide: ROUTES, + multi: true, + deps: [Injector], + useFactory: (injector: Injector) => buildTabMainRoutes(injector, { + component: CoreMainMenuMorePage, + }), + }, ], declarations: [ CoreMainMenuMorePage, diff --git a/src/core/features/settings/settings.module.ts b/src/core/features/settings/settings.module.ts index 22dbbac9e..2c7fe2a4d 100644 --- a/src/core/features/settings/settings.module.ts +++ b/src/core/features/settings/settings.module.ts @@ -16,7 +16,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { Routes } from '@angular/router'; import { AppRoutingModule } from '@/app/app-routing.module'; -import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module'; +import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreSettingsHelperProvider } from './services/settings-helper'; @@ -41,7 +41,7 @@ const mainMenuMoreRoutes: Routes = [ @NgModule({ imports: [ AppRoutingModule.forChild(appRoutes), - CoreMainMenuMoreRoutingModule.forChild({ siblings: mainMenuMoreRoutes }), + CoreMainMenuTabRoutingModule.forChild({ siblings: mainMenuMoreRoutes }), ], providers: [ { diff --git a/src/core/features/tag/tag-lazy.module.ts b/src/core/features/tag/tag-lazy.module.ts index dca55c3f5..1fbe988b1 100644 --- a/src/core/features/tag/tag-lazy.module.ts +++ b/src/core/features/tag/tag-lazy.module.ts @@ -12,31 +12,42 @@ // 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'; -const routes: Routes = [ - { - path: 'index', - loadChildren: () => import('@features/tag/pages/index/index.page.module').then(m => m.CoreTagIndexPageModule), - }, - { - path: 'search', - loadChildren: () => import('@features/tag//pages/search/search.page.module').then(m => m.CoreTagSearchPageModule), - }, - { - path: 'index-area', - loadChildren: () => import('@features/tag/pages/index-area/index-area.page.module').then(m => m.CoreTagIndexAreaPageModule), - }, - { - path: '', - redirectTo: 'search', - pathMatch: 'full', - }, -]; +import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; + +function buildRoutes(injector: Injector): Routes { + return [ + { + path: 'index', + loadChildren: () => import('@features/tag/pages/index/index.page.module').then(m => m.CoreTagIndexPageModule), + }, + { + path: 'search', + loadChildren: () => import('@features/tag//pages/search/search.page.module').then(m => m.CoreTagSearchPageModule), + }, + { + path: 'index-area', + loadChildren: () => + import('@features/tag/pages/index-area/index-area.page.module').then(m => m.CoreTagIndexAreaPageModule), + }, + ...buildTabMainRoutes(injector, { + redirectTo: 'search', + pathMatch: 'full', + }), + ]; +} @NgModule({ - imports: [RouterModule.forChild(routes)], exports: [RouterModule], + providers: [ + { + provide: ROUTES, + multi: true, + deps: [Injector], + useFactory: buildRoutes, + }, + ], }) export class CoreTagLazyModule { } diff --git a/src/core/features/user/user.module.ts b/src/core/features/user/user.module.ts index 8ffbebe6c..669042ec1 100644 --- a/src/core/features/user/user.module.ts +++ b/src/core/features/user/user.module.ts @@ -15,7 +15,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { Routes } from '@angular/router'; -import { CoreMainMenuMoreRoutingModule } from '@features/mainmenu/pages/more/more-routing.module'; +import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CORE_SITE_SCHEMAS } from '@services/sites'; import { SITE_SCHEMA, OFFLINE_SITE_SCHEMA } from './services/database/user'; import { CoreUserComponentsModule } from './components/components.module'; @@ -37,7 +37,7 @@ const routes: Routes = [ @NgModule({ imports: [ - CoreMainMenuMoreRoutingModule.forChild({ siblings: routes }), + CoreMainMenuTabRoutingModule.forChild({ siblings: routes }), CoreUserComponentsModule, ], providers: [