I have this structure in mine app.component.html:
<app-main-nav></app-main-nav>
<router-outlet></router-outlet>
These are my routes:
const routes = [
{path: "", redirectTo: "home", pathMatch: "full"},
{
path: "posts", component: PostsComponent,
children: [{
path: ":id",
component: PostComponent
}];
}
]
I'm trying to access options on page PostComponentin MaiNavComponent, but this causes an error.
export class MainNavComponent implements OnInit {
constructor( private route: ActivatedRoute) {
route.params.subscribe(console.log)
}
}
How can I get :idout PostComponentof MainNavComponent?
I tried to do this:
route.params.subscribe(console.log)
Here I get an empty object.
And this:
route.firstChild.params.subscribe(console.log)
Unable to read params properties from null
source
share