2

Is there any way so that I can load different component on the same route(in my case the root route).

Basically I want to see if the user is logged in, if he is logged in, the dashboard component will be loaded, if is he not logged in, the home component will be loaded

And again just to make the question clear, I don't want to redirect the user to a DIFFERENT route using auth guards. I want to load different components on the same route

3
  • Take a look at Auth Guard: netbasal.com/… Commented Nov 30, 2017 at 6:27
  • There are guards you can work with. Check this link blog.thoughtram.io/angular/2016/07/18/guards-in-angular-2.html. It gives a good understanding of guards. Commented Nov 30, 2017 at 6:28
  • I have used guards and as far as I know guards as the name suggest can only guard the route whether to allow access or no, in case no access should be allowed we can redirect the user to a different route. But I don't want the user to be redirect to a different route in this case, but the root route itself should load different component based on my condition Commented Nov 30, 2017 at 6:31

1 Answer 1

2

If you don't want to use guards and this is what you mentioned in your question, you can simply use ngIf.

Example:

<div *ngIf="this.authService.hasPermissionForDashboard()">
 <app-dashboard><app-dashboard>
</div>
<div *ngIf="this.authService.hasNotPermissionForDashboard()">
 <app-home><app-home>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

I was also thinking of this, but thought there must be some better way. Assuming there is no other "standard" way. I can get away with this. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.