I'm having trouble assigning default values to my route parameters inside of my component ts class. I want the genreId to be null by default. I want monetization, sortBy, and page to have default values. I'm not sure if I'm supposed to do this inside of ngOninit or if I'm supposed to do this somehow inside of my app routing module.
export class MoviesPageComponent implements OnInit {
movies?: MovieData;
genreId?: string | null = null;
monetization?: string | null;
sortBy?: string | null;
page?: string | null;
constructor(private getMovies: GetMoviesService,
private route: ActivatedRoute) { }
ngOnInit(): void {
this.route.queryParamMap.subscribe((params: ParamMap) => {
this.genreId = params.get('genreId')
})
this.route.paramMap.subscribe((params: ParamMap) => {
this.monetization = params.get('monetization');
this.sortBy = params.get('sortBy');
this.page = params.get('page');
});
if (this.genreId === null) {
this.getMovies.moviesData(this.monetization, this.sortBy, this.page).subscribe((movieData: MovieData) => {
if (movieData !== undefined) {
this.movies = movieData;
}
})
}
}
}
My app routing module array looks like this.
const routes: Routes = [
{path: ' ', pathMatch: 'full', redirectTo: '/:monetization/:sortBy/:page'},
{path: '/:monetization/:sortBy/:page/', pathMatch: 'full', component: MoviesPageComponent}
];