Я хочу, чтобы при нажатии на пункт меню карт он перенаправлялся на компонент карт, но я не смог этого добиться. Я попытался добавить маршрут, чтобы перенаправить его в приведенный ниже код, но не повезло.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouterModule, Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { AppRouteGuard } from './shared/common/auth/auth-route-guard';
import { NotificationsComponent } from './shared/layout/notifications/notifications.component';
import { NgxSpinnerService } from 'ngx-spinner';
import { MapsComponent } from './shared/common/maps/maps.component';
@NgModule({
imports: [
RouterModule.forChild([
{
path: 'app',
component: AppComponent,
canActivate: [AppRouteGuard],
canActivateChild: [AppRouteGuard],
children: [
{
path: '',
children: [
{ path: 'notifications', component: NotificationsComponent },
{ path: '', redirectTo: '/app/main/dashboard', pathMatch: 'full' }
]
},
{
path: 'shared',
children: [
{ path: 'maps', component:MapsComponent},
{ path: '', redirectTo: '/app/shared/common/maps', pathMatch: 'full' }
]
},
{
path: 'main',
loadChildren: () => import('app/main/main.module').then(m => m.MainModule), //Lazy load main module
data: { preload: true }
},
{
path: 'admin',
loadChildren: () => import('app/admin/admin.module').then(m => m.AdminModule), //Lazy load admin module
data: { preload: true },
canLoad: [AppRouteGuard]
},
{
path: '**', redirectTo: 'notifications'
},
]
},
])
],
exports: [RouterModule]
})
export class AppRoutingModule {
constructor(
private router: Router,
private spinnerService: NgxSpinnerService
) {
router.events.subscribe((event) => {
if (event instanceof RouteConfigLoadStart) {
spinnerService.show();
}
if (event instanceof RouteConfigLoadEnd) {
spinnerService.hide();
}
if (event instanceof NavigationEnd) {
document.querySelector('meta[property=og\\:url').setAttribute('content', window.location.href);
}
});
}
}
Пункт меню, который я добавил в макет:
new AppMenuItem('Maps', '', 'flaticon-map-location', '/app/shared/common/maps')