MOBILE-3833 course: Change courses routes to fix links

main
Dani Palou 2022-03-18 10:13:56 +01:00
parent 265a170b13
commit 1211bf1c03
4 changed files with 59 additions and 73 deletions

View File

@ -12,35 +12,53 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { NgModule } from '@angular/core'; import { Injector, NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; 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 = [ function buildRoutes(injector: Injector): Routes {
{ return [
path: '', {
redirectTo: 'list', path: 'my',
pathMatch: 'full', data: {
}, mainMenuTabRoot: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME,
{ },
path: 'categories', loadChildren: () => import('./pages/my/my.module').then(m => m.CoreCoursesMyCoursesPageModule),
redirectTo: 'categories/root', // Fake "id". },
pathMatch: 'full', {
}, path: 'categories',
{ redirectTo: 'categories/root', // Fake "id".
path: 'categories/:id', pathMatch: 'full',
loadChildren: () => },
import('./pages/categories/categories.module') {
.then(m => m.CoreCoursesCategoriesPageModule), path: 'categories/:id',
}, loadChildren: () =>
{ import('./pages/categories/categories.module')
path: 'list', .then(m => m.CoreCoursesCategoriesPageModule),
loadChildren: () => },
import('./pages/list/list.module') {
.then(m => m.CoreCoursesListPageModule), path: 'list',
}, loadChildren: () =>
]; import('./pages/list/list.module')
.then(m => m.CoreCoursesListPageModule),
},
...buildTabMainRoutes(injector, {
redirectTo: 'my',
pathMatch: 'full',
}),
];
}
@NgModule({ @NgModule({
imports: [RouterModule.forChild(routes)], exports: [RouterModule],
providers: [
{
provide: ROUTES,
multi: true,
deps: [Injector],
useFactory: buildRoutes,
},
],
}) })
export class CoreCoursesLazyModule {} export class CoreCoursesLazyModule {}

View File

@ -50,17 +50,10 @@ const mainMenuHomeChildrenRoutes: Routes = [
}, },
]; ];
const mainMenuHomeSiblingRoutes: Routes = [ const routes: Routes = [
{
path: 'courses',
loadChildren: () => import('./courses-lazy.module').then(m => m.CoreCoursesLazyModule),
},
];
const mainMenuTabRoutes: Routes = [
{ {
path: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME, 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: [ imports: [
CoreMainMenuHomeRoutingModule.forChild({ CoreMainMenuHomeRoutingModule.forChild({
children: mainMenuHomeChildrenRoutes, children: mainMenuHomeChildrenRoutes,
siblings: mainMenuHomeSiblingRoutes,
}), }),
CoreMainMenuRoutingModule.forChild({ children: mainMenuTabRoutes }), CoreMainMenuRoutingModule.forChild({ children: routes }),
CoreMainMenuTabRoutingModule.forChild(mainMenuTabRoutes), CoreMainMenuTabRoutingModule.forChild(routes),
], ],
exports: [CoreMainMenuRoutingModule], exports: [CoreMainMenuRoutingModule],
providers: [ providers: [

View File

@ -12,53 +12,29 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Injector, NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, ROUTES, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { CoreSharedModule } from '@/core/shared.module'; import { CoreSharedModule } from '@/core/shared.module';
import { CoreBlockComponentsModule } from '@features/block/components/components.module'; import { CoreBlockComponentsModule } from '@features/block/components/components.module';
import { CoreCoursesMyCoursesPage } from './my'; import { CoreCoursesMyCoursesPage } from './my';
import { CoreMainMenuComponentsModule } from '@features/mainmenu/components/components.module'; 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 { const routes: Routes = [
return [ {
{ path: '',
path: '', component: CoreCoursesMyCoursesPage,
component: CoreCoursesMyCoursesPage, },
data: { ];
mainMenuTabRoot: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME,
},
},
{
path: 'list',
loadChildren: () =>
import('../list/list.module')
.then(m => m.CoreCoursesListPageModule),
},
...buildTabMainRoutes(injector, {
redirectTo: '',
pathMatch: 'full',
}),
];
}
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forChild(routes),
CoreSharedModule, CoreSharedModule,
CoreBlockComponentsModule, CoreBlockComponentsModule,
CoreMainMenuComponentsModule, CoreMainMenuComponentsModule,
], ],
providers: [
{
provide: ROUTES,
multi: true,
deps: [Injector],
useFactory: buildRoutes,
},
],
declarations: [ declarations: [
CoreCoursesMyCoursesPage, CoreCoursesMyCoursesPage,
], ],

View File

@ -27,7 +27,7 @@ import { CoreDashboardHomeHandler } from './dashboard-home';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuHandler { export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuHandler {
static readonly PAGE_NAME = 'my'; static readonly PAGE_NAME = 'courses';
name = 'CoreCoursesMyCourses'; name = 'CoreCoursesMyCourses';
priority = 900; priority = 900;