#How To Get Route Path Parameters In Non-Routed Angular Components?
9 messages · Page 1 of 1 (latest)
Not easily. Why not put nav-bar in the route?
Because I would have to to add nav bar to every component in routing, but if there is no other way I will do that
const routes: Routes = [
{
path: '',
component: MainLayoutComponent,
children: [
// your routes here
]
}
]
App component:
<router-outlet /> <!-- <- main routes (in this example just MainLayoutComponent) render here -->
Main layout:
<nav-bar></nav-bar>
<router-outlet /> <!-- <- children of main route render here -->
But that still won't allow the navbar to access the child route's parameters. @kindred nova what's your usecase. If the navbar is global for all routes, and not part of route X, why does it need to access the parameters of route X?
I have like search bar in navbar and i just need to get route parameter on init
OK, but the actual search will probably be done by the routed component, and the results will be displayed by the routed component as well, won't it? So the search bar needs to somehow communicate with the routed component somehow (via a service probably). So the routed component could tell the navbar, via the same service, what the current search query is.
I'm making a lot of guesses here. That's why I asked for your use-case. Your very short answer doesn't help much.
Sorry, but you think well, it is as you said
Okey, then I will create service and communicate them via this service