Reputation: 6468
I have a route that is openend when the user clicks a link in an email. That link contains some tokens and IDs which need to be inspected. Depending on the outcome of the inspection I would redirect the user to the respective routes. For example, the user could be routed to an error page, to a register/logon page or directly to his dashboard.
Furthermore, I don't want to do the inspection in the component, because I don't want any template to be rendered during the checks. The first page the user should see is the one he finally gets routed to. So, I do the checks in a guard
.
Nevertheless I need to configure a component in the route config, which eventually will never be rendered. Of course, I could define an arbitrary component there, but actually the guard
alone would be sufficient here.
I admit, this is more an esthetic thing but a real problem :) On the other hand, there could be a more straight-forward approach, I don't know about. Any ideas/opinions on that?
Upvotes: 2
Views: 1008
Reputation: 15683
I found myself in the same situation as described in your question, yet, I disliked the idea to create a "DummyComponent" just to satisfy the router api.
Hence, I went with an empty children array:
path: '**',
canActivate: [RouteGuard],
children: []
Then your RouteGuard
can take over and do the redirection magic dynamically basing it's routing decision on the current application state.
Upvotes: 2