Search code examples
angularangular-ui-router

How to get params form route pass to multi component in angular


code is : in course component have other component how to pass params on it ? const routes: Routes = [ { path: '', component: HomeComponent }, { path: ':courseUrl', component: CourseComponent, } ]


Solution

  • inside constructor at course-component.ts u could subscribe to query parameters like this

    constructor(
        ...
        /* your other codes*/
        ...
        public route: ActivatedRoute,
    ){
        ...
        /* your other codes*/
        ...
        this.route.params.subscribe((params) => {
             console.log(params);
        });
    }
    

    u will see courseUrl at your console, change console.log(params) to something like this.courseUrlParam = params to store that params to a variable