I have this routing table:
// Routing array - set routes to each html page
const appRoutes: Routes = [
{ path: '', redirectTo: '/courses', pathMatch: 'full' },
{ path: 'courses', component: CourseListComponent, pathMatch: 'full'},
{ path: 'courses/:id', component: CourseDetailComponent, pathMatch: 'full' },
{ path: 'courses/:id/unit/:unitId', component: CoursePlayComponent,
children: [
{ path: '', component: CourseListComponent },
{ path: 'lesson/:lessonId', component: CourseLessonComponent, data: 'lesson },
{ path: 'quiz/:quizId', component: CourseQuizComponent, data: 'quiz, }
]},
{ path: '**', component: PageNotFoundComponent, pathMatch: 'full' }];
//Course-Play.component
constructor(private courseService: CourseService,
private route: ActivatedRoute,
private router: Router,
public sanitizer: DomSanitizer) {
route.url.subscribe(() => {
console.log(route.snapshot.children.data); }); // <-- undefined
}
ngOnInit() {
// this is what I want to do but I don't know how
if (this.route.snapshot.children.data == 'lesson) {
// activate lesson children
}
else {
// activate quiz children
}
}
In ngOnInit in course-play I want to know if the route is lesson/:lessonId or quiz/:quizId. I only need to know if there's lesson or quiz in the route and then activate different child. I know how to do it with params (with route.snapshot) but not with a static text.
EDIT: tried to use data but it's not working