Within our Angular-7-Application, we rely on @ngrx and @ngrx/router-store to incorporate query params into the state.
Many parts of the application consist of paginated lists. Each list is represented as a component with the Pagination-Component integrated alongside.
The current page number is stored in the URL through the query parameter: user/:userId/agent?page=0
with the PaginationComponent fetching the current page from
state.router.state.queryParams.page
. However, if a user accesses the URL user/:userId/agent
, queryParams.page
will return undefined.
We could resolve this issue by utilizing
state.router.state.queryParams.page || 0
in each component, but I am curious if there is a simpler solution - can a Route lacking query params be redirected to a Route with query params?
I attempted the most straightforward redirect method:
{ path: 'user/:userId/agent', redirectTo: '/user/:userId/agent?page=0', pathMatch: 'full' },
{ path: 'user/:userId/agent?page=0', component: AgentListComponent },
yet encountered an error:
Error: Cannot match any routes. URL Segment: 'user/max/agent'
.
The only related feature request I came across was mentioned in this report, where the same error was highlighted.