I've the following route config:
const routes: Routes = [
// another routes
{ component: UsersListComponent, path: 'users' }
];
I want to "automatically" include some default QUERY parameters when something route to this.
E.g.:
The route /users
become /users?p=1s&15
, when it has NO query parameters.
I just got stucked trying to do it with guards (I'm not even sure that's the best choice for do this). Below is a piece of my actual code:
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
// Just for make it clear:
if (state.url === '/users') {
this.router.navigate([], {
queryParams: {
p: 1,
s: 15
},
relativeTo: this.activatedRoute
});
}
return true;
}
}