So, there can be entry to my app in multiple ways.
http://localhost:4200 and http://localhost:4200/home
If the link to my app (from an outside app) has a query param on it, I want to grab it. I created a QueryParamCheckGuard
which is @Injectable({providedIn: 'root',})
. For now, I just have a console.log('In QueryParamCheckGuard');
in both the canActivate
and canActivateChild
methods to see when it gets called. Right now, it's not getting called on any path that redirects.
In my app, I have sub-projects. The main routing looks like this:
{
path: 'home',
canActivate: [QueryParamCheckGuard],
canActivateChild: [QueryParamCheckGuard],
data: {
path: 'App Home Path',
},
loadChildren:
'../../projects/home-app/src/app/app.module#HomeAppModule',
},
{
path: '',
canActivate: [QueryParamCheckGuard],
canActivateChild: [QueryParamCheckGuard],
data: {
path: 'App Empty Path',
},
redirectTo: '/home',
pathMatch: 'full',
}
In the HomeAppModule, the routing is this:
{
path: 'home',
component: AppComponent,
canActivate: [QueryParamCheckGuard],
canActivateChild: [QueryParamCheckGuard],
data: {
path: 'Sub-proj Home Path',
},
children: [
{ path: '', component: HomePageComponent },
],
}
The routing all works correctly, but when I enter http://localhost:4200?id=test, the QueryParamCheckGuard is not being called on the main app's path: ''
route that redirects to the main app's path: 'home'
and by the time it gets to the sub-project's path: 'home'
, the id query param is stripped off. I know it's not getting called from the other routes because I added a path property to each path's data that identifies each path. I then console.log(route.data.path);
.
If I hit http://localhost:4200/home?id=test, the QueryParamCheckedGuard is hit and I can grab the id query param. Aside from requiring all outside apps to call the /home url, am I missing something to get the path that redirects to home to grab the query param?