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
// 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 {}

View File

@ -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: [

View File

@ -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,
],

View File

@ -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;