Reputation: 990
I am building Angular 2 application and having a little conceptual problem.
In my application, I have a dashboard page which contains search-bar, navigation list and a router-outlet for the content to show. In my navigation list I have several links which include :
When I click on each of the links I am getting navigated to /items which is handled by ItemsModule and ItemsComponent. I have already implemented the routes and the links but I am struggling with the idea of how to determine which link I've used.
I thought about several ways to implement it :
In addition, as I mentioned above, I have a search-bar to search for a specific item (whether I am at 'All' / 'My' / 'Pending' items). I wonder how can I combine all of the navigations and routing and get it all work together.
Let me know if someone has figured a way to "solve" my problem.
Upvotes: 2
Views: 878
Reputation:
I would use 3 paths:
{path: 'items', component: ItemsComponent},
{path: 'items/:type', component: ItemsComponent},
{path: 'items/:type/:searchString', component: ItemsComponent}
In the component:
this._route.params.subscribe(p => {
var searchString = p["searchString"];
switch(p["type"]) {
case 'all':
//do something
break;
case 'mine':
//do something
break;
case 'pending':
//do something
break;
default:
//do something
break;
}
}
Upvotes: 1