angular2-routing

Nested Router Outlet With Name Not Working

╄→尐↘猪︶ㄣ 提交于 2021-01-28 18:20:58
问题 I'm struggling with nested router-outlets. My situations looks like this: I have a <router-outlet> in my app.components.html Then I lazy load my desktop.module.ts module via the url: /d . It looks like this: const routes: Routes = [ { path: 'workout', component: WorkoutComponent, outlet: 'desktop'}, { path: '', component: DesktopComponent, pathMatch: 'full' } ]; @NgModule({ imports: [ CommonModule, IonicModule, RouterModule.forChild(routes) ], declarations: [WorkoutComponent, DesktopComponent

Angular Router Event Name

天大地大妈咪最大 提交于 2021-01-27 21:13:11
问题 The Angular(2+) router has an events property that is a rxjs subject. Once subscribed, you are able to listen for events like: router.events.subscribe((event: Event) => { console.log(event) }); but the problem is you have no way to obtain the event type since it listens for all events. A hacky solution is you can inspect the constructor name of the event like: router.events.subscribe((event: Event) => { if(event.constructor.name === 'NavigationStart') { loadingService.start(); } else if(event

How to hide the parent component when loading a child component in Angular 2

拜拜、爱过 提交于 2021-01-27 04:40:29
问题 In my current project, I have the following view When the page loads, the Parent Item Description should visible and the Selected sub item description should not visible. When I select a Sub Item x , the Parent Item Description should be hidden and only the Selected sub item description visible. I have created the following route for this { path: 'main/:id', component: MainComponent, children: [ { path: '', component: MainComponent, pathMatch: 'full', }, { path: 'sub/:id', component:

CanDeactivate changing the window history

时间秒杀一切 提交于 2021-01-03 08:55:31
问题 I am facing some issue with canDeactivate() whenever it returns false it is changing the window history as when it became true and if i hit the back button. I am navigating to some other URL or out of the app itself. Please help me 回答1: Here is the issue, but it still isn't fixed. As a workaround, you can manually put the active url back to the history: export class CanDeactivateGuard implements CanDeactivate<any> { constructor( private readonly location: Location, private readonly router:

CanDeactivate changing the window history

白昼怎懂夜的黑 提交于 2021-01-03 08:53:30
问题 I am facing some issue with canDeactivate() whenever it returns false it is changing the window history as when it became true and if i hit the back button. I am navigating to some other URL or out of the app itself. Please help me 回答1: Here is the issue, but it still isn't fixed. As a workaround, you can manually put the active url back to the history: export class CanDeactivateGuard implements CanDeactivate<any> { constructor( private readonly location: Location, private readonly router:

Angular: Unit testing lazy-loaded modules with routing

霸气de小男生 提交于 2020-12-07 03:02:33
问题 I'm facing some issues testing lazy-loaded modules in Angular. This is my .spec file: import { Location } from '@angular/common'; import { TestBed, ComponentFixture } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { Router } from '@angular/router'; import { routes } from './app-routing.module'; import { AppComponent } from './app.component'; import { AppConfigService } from './services/appConfig.service'; import { TranslateModule } from '

Nested routing with nested modules

≯℡__Kan透↙ 提交于 2020-12-03 07:27:20
问题 I am working on an Angular 2 app for the first time. I have routing similar to this - /home /projects/ /projects/:id/members /projects/:id/members/:id/tasks From all the references, tutorials and articles I could find on the internet. I only found approach similar to this - [ { path: "home", component: HomeComponent }, { path: "", redirectTo: "home", pathMatch: "full" }, { path: 'projects', component: ProjectComponent, children: [ { path: ':id', component: ProjectDetailsComponent, children: [