Bug with optional routes: move the error case in the end of all routes

This commit is contained in:
argirok 2022-06-22 17:20:19 +03:00
parent 513bb83769
commit 1839b3a82a
1 changed files with 20 additions and 21 deletions

View File

@ -95,8 +95,7 @@ const routes: Routes = [
data: {hasSidebar: false}
},
{path: 'user-info', loadChildren: () => import('./login/libUser.module').then(m => m.LibUserModule)},
{path: 'error', component: OpenaireErrorPageComponent},
{path: '**', pathMatch: 'full', component: OpenaireErrorPageComponent}
{path: 'error', component: OpenaireErrorPageComponent}
];
@NgModule({
@ -107,7 +106,7 @@ const routes: Routes = [
})
export class AppRoutingModule {
subs = [];
routes =[];
enabledRoutes =[];
ngOnDestroy() {
for (let sub of this.subs) {
sub.unsubscribe();
@ -118,17 +117,17 @@ export class AppRoutingModule {
if (data) {
if (data['pages']) {
for (var i = 0; i < data['pages'].length; i++) {
this.routes[data['pages'][i]['route']] = data['pages'][i]['isEnabled'];
this.enabledRoutes[data['pages'][i]['route']] = data['pages'][i]['isEnabled'];
}
}
this.getRoutes();
this.getOptionalRoutes();
}
},
error => {
// this.handleError('Error getting community information (e.g. pages,entities) for community with id: ' + this.communityId, error);
}));
}
getRoutes(){
getOptionalRoutes(){
let optionalRoutes = [
// Deposit Pages
{ path: 'participate/deposit-datasets', redirectTo: 'participate/deposit/learn-how', pathMatch: 'full'},
@ -145,12 +144,12 @@ export class AppRoutingModule {
{ path: 'participate/direct-claim', loadChildren: () => import('./claims/directLinking/directLinking.module').then(m => m.LibDirectLinkingModule)},
{path: 'develop', loadChildren: () => import('./develop/develop.module').then(m => m.DevelopModule)}
];
for (var i = 0; i <optionalRoutes.length; i++) {
if(this.routes["/"+optionalRoutes[i].path]){
if(this.enabledRoutes[("/"+optionalRoutes[i].path)]){
this.router.config.push(optionalRoutes[i]);
}
}
this.router.config.push({path: '**', pathMatch: 'full', component: OpenaireErrorPageComponent});
return routes;
}
}