Angular 2 Multiple routes for logged in user and guest

78 views
Skip to first unread message

Rakesh Roy

unread,
Jan 17, 2017, 5:02:25 AM1/17/17
to Angular
I want to create a blog where user can signup and can post image story with angular2.

Now when user visit my site they will see only signup and login form [Signup and login component with routes /signup[default] and /login ]

Now when they logged in into site they will see  header , side menu [post, help, settings  everything under /dashboard like /dashboard/post , /dashboard/settings]

when user in dashboard they will see content mid of the page for all the /dashboard routes.

now how to configure routes for that and how to use two <router-outlet></router-outlet> [ for signup and login]  and <router-outlet></router-outlet> [ for dashboard components].


Thank you
Content part of dashboard.png

Sander Elias

unread,
Jan 18, 2017, 12:11:29 AM1/18/17
to Angular
Hi Rakesh,

You can add a top level route, that distinguishes on login state.
Once you log in, you pull in a component that serves what you now use at the top level.
Another solution is to use ngIf to check the login-state. something like this will do:

<span *ngIf="userAuthenticated"><router-outlet></router-outlet></span>
<span *ngIf="!userAuthenticated"><sign-in-on></sign-in-on></span>

Does that help you a bit?
Regards
Sander
Reply all
Reply to author
Forward
0 new messages