In our Angular-7-Application, we use @ngrx and @ngrx/router-store to get the query params into the state.
A few components of the application are paginated lists. We have every list as a component and the Pagination-Component included in every list.
The current page is stored in the URL as a query Parameter: user/:userId/agent?page=0
and the PaginationComponent gets the current page from state.router.state.queryParams.page
. However, if a user accesses the URL user/:userId/agent
, queryParams.page
returns undefined.
We could solve this by using state.router.state.queryParams.page || 0
in every component but I wonder, if there is an easier way - can a Route without query params be redirect to a Route with query params?
I tried using the most obvious redirect:
{ path: 'user/:userId/agent', redirectTo: '/user/:userId/agent?page=0', pathMatch: 'full' },
{ path: 'user/:userId/agent?page=0', component: AgentListComponent },
but I get Error: Cannot match any routes. URL Segment: 'user/max/agent'
.
The only feature request I found was this one where the error above appears.